[Python-Dev] int/float freelists vs pymalloc

Christian Heimes lists at cheimes.de
Fri Feb 8 20:43:02 CET 2008


Tim Peters wrote:
> pymalloc ensures 8-byte alignment.  This is one plausible reason to
> keep the current int free list:  an int object struct holds 3 4-byte
> members on most boxes (type pointer, refcount, and the int's value),
> and the int freelist code uses exactly 12 bytes for each on most
> boxes.  To keep 8-byte alignment, pymalloc would have to hand out a
> 16-byte chunk per int object, wasting a fourth of the space (pymalloc
> always rounds up a requested size to a multiple of 8, and ensures the
> address returned is 8-byte aligned).

Given the background information Python's long implementation could
probably optimized. In 3.0 a long has 3 4-byte members (ref count,
ob_size and *ob_type) plus one to many unsigned shorts (2 bytes each) to
hold the value. If pymalloc aligns the objects at 8 byte address
boundaries wouldn't it be better and slightly faster to use unsigned
ints instead of unsigned shorts?

Christian


More information about the Python-Dev mailing list