[Python-Dev] collections module (original) (raw)

Raymond Hettinger python at rcn.com
Sat Jan 10 13:36:21 EST 2004


> I don't know whether the overallocation would make similar-sized room > at both ends, or whether it would take the current operation into > account. For the specific case of queues, we may find that doing > just the copying might be sufficient, with no need to go to the > allocator.

Hm. An idea: don't bother overallocating when inserting in the front, but do keep the free space in the front if possible. Then recommend that queus are implemented using append(x) and pop(0), rather than using insert(0, x) and pop().

That is a reasonable approach and probably not difficult to implement.

Since external code (outside listobject.c) may already be relying on ob_item, the approach should just change that field to always point to the start of valid data. A new field would have to keep a pointer to the actual allocated block.

Raymond Hettinger

################################################################# ################################################################# ################################################################# ##### ##### ##### ################################################################# ################################################################# #################################################################



More information about the Python-Dev mailing list