#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Location
    Bombay, India
    Posts
    159
    Rep Power
    13

    Memory allocation.


    Hi,
    I wanted to know how much memory is set aside for each data type...or the "objects" rather? Like in C/C++, 'int' took up 4 bytes...'char' 2 bytes and so on....I just wanted to know abt Python objects....that also includes lists, tuples, dictionaries, etc.


    Thanks,
    Subha
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    London, England
    Posts
    1,585
    Rep Power
    1373

    Use The Source, Luke


    There is no simple answer to the question, since it will vary depending on the OS and C compiler, as well as the flags that Python was compiled with.

    However you can find all the information you need by looking at the C header files, which should be in an 'include' directory in your Python installation. The place to start is "object.h" which defines the C structs that represent the main Python types.

    Good Luck.

    Dave - The Developers' Coach
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Location
    Bombay, India
    Posts
    159
    Rep Power
    13
    Thanks Dave!
    I was searching thru' the net and this piece caught my eye... thought I wld share it with the Python ppl....

    Memory sizes of built-in datatypes----------->

    Integer ...............:12 bytes
    Long Integer.........:12 bytes + (nbits/16 + 1)*2 bytes
    Floats..................:16 bytes
    Complex...............:24 bytes
    List.....................:16 bytes + 4 bytes for each item
    Tuple...................:16 bytes + 4 bytes for each item
    String..................:20 bytes + 1 byte per character
    Dictionary.............:24 bytes + 12*2n bytes, n=log2(nitems) + 1



    Rgds,
    Subha

IMN logo majestic logo threadwatch logo seochat tools logo