memory usage

Tim Peters tim.one at comcast.net
Sun May 11 00:09:20 EDT 2003


[Duncan Booth]
> If the compiler decided to pad all the structures an empty dictionary
> occupies 160 bytes, even though only 124 of them are used.
> ...
> Actually it seems that windows isn't inserting any padding, so
> its only 124  bytes overhead. I must have misunderstood the bit about
> default structure member alignment being 8 bytes.

The default MSVC packing option is /Zp8, which basically means it never pads
more than is needed for "natural" alignment of struct members.  Each member
of dict object struct has a natural alignment of 4 and consumes 4 bytes on a
32-bit box, so no padding is needed.

Note that a dict actually consumes more memory than that, though:  because
dicts participate in cyclic gc, a dict is always allocated with a PyGC_Head
union immediately before the dict struct.  There's 12 bytes worth of data in
a PyGC_Head, but MSVC pads it to 16 to ensure natural alignment of the "long
double dummy" member.  So a dict actually consumes 124+16 = 140 bytes under
MSVC.






More information about the Python-list mailing list