Queue not releasing memory

Tim Peters tim_one at email.msn.com
Mon Sep 13 22:37:42 EDT 1999


[Nathan Clegg]
> ...
> I do need the thread-safety of the Queue class.  The large size
> requirement is only an extreme situation, which is why it is important
> that it backs down afterward.

Still unclear why "backing down" is important.  The VM high-water mark is
really of no practical interest on most systems.  Python isn't using the
memory any more, so it's not costing anything except a hole in the address
space (which your libc malloc may or may not release to the OS someday, or
may or may not reuse for its own purposes again -- why do you care?).

> ...
> Is there no way to remove an element from a list without making a copy?

Python lists are contiguous vectors of C pointers.  If you remove an element
from "the front" (as Queue does), all the remaining elements have to "slide
left" one position.  If it's not the queueness but the thread safety that
attracts you, subclass Queue and remove elements from "the rear" (i.e., use
x.pop() instead of del x[0] -- then it acts like a stack instead of a
queue).  Then copying will rarely be needed.  If you want both a queue and
no-copying, implement a two-pointer circular buffer.

> append() doesn't need a copy.

It usually doesn't; it certainly may.

> I was under the impression that lists were internally represented by a
> more dynamic form.

I believe you <wink>.

purge-your-soul-of-falsehoods-and-fear-of-artificial-integers-ly y'rs  - tim






More information about the Python-list mailing list