Pop a list from beginning ? and memory saving...
James T. Dennis
jadestar at idiom.com
Wed Jun 19 15:52:41 EDT 2002
Aahz <aahz at pythoncraft.com> wrote:
> In article <aep4jb$1q8h$1 at news.idiom.com>,
> James T. Dennis <jadestar at idiom.com> wrote:
>> It might be better to have a hack to the implementation of the
>> list primitives --- so they defer the shift of remaining elements
>> until GC. The head of the list could point at the first none
>> deleted item. Then pop(0) could be implemented in O(1) time and
>> the garbage collector would eventually come along to do it's
>> job.
> While this might be a worthwhile optimization, it has absolutely nothing
> to do with GC. Each time an element were popped off the front, its
> object would be decreffed and possibly deleted. GC runs completely
> independently of individual objects.
Sorry, I was speaking abstractly about garbage collection, I know
nothing about Python's GC implementation. Perhaps it would be an
opportunity to augment Python's GC. Some containers (and even
some classes) could implement their own compaction routines that
could be called by the GC.
More information about the Python-list
mailing list