[Python-Dev] constant/enum type in stdlib
greg.ewing at canterbury.ac.nz
Mon Nov 29 21:47:23 CET 2010
Rob Cliffe wrote:
> But when a frozen list a.k.a. tuple would be created - either directly,
> or by setting a list's mutable flag to False which would really turn it
> into a tuple - the size *would* be known.
But at that point the object consists of two memory blocks -- one
containing just the object header and a pointer to the items, and
the other containing the items.
To turn that into a true tuple structure would require resizing
the main object block to be big enough to hold the items and
copying them into it. The main object can't be moved (because
there are PyObject *s all over the place pointing to it), so
if there's not enough room at its current location, you're out
So lists frozen after creation would have to remain as two blocks,
making them second-class citizens compared to those that were
created frozen. Either that or store all lists/tuples as two
blocks, and give up some of the performance advantages of the
current tuple structure.
More information about the Python-Dev