Looking for info on Python's memory allocation

R Toop toop82 at comcast.net
Tue Oct 11 04:52:26 CEST 2005


wherein Tim gently corrects my brash guess that Python lists are
The example's linearly-constructed list is allocated by doubling storage,
copying & freeing (cf realloc).
The result that the process virtual memory is twice the size of the list,
more or less, with the freed predecessor chunks on the process heap, but not
released to the operating system.
This only SEEMS to use as much memory as pointer-linked elements would do.
Hope this URL helps.


"Steven D'Aprano" <steve at REMOVEMEcyber.com.au> wrote in message
news:434B1A99.8040107 at REMOVEMEcyber.com.au...
> Can somebody help me please? I've spent a fruitless
> hour googling with no luck.
> I'm discussing memory allocation techniques with
> somebody, and I'm trying to find a quote from -- I
> think -- Tim Peters where he discusses the way Python
> allocates memory when you append to lists. In basic
> terms, he says that every time you try to append to a
> list that is already full, Python doubles the size of
> the list. This wastes no more than 50% of the memory
> needed for that list, but has various advantages -- and
> I'm damned if I can remember exactly what those
> advantages were.
> Can anyone point me in the right direction?
> Thanks,
> -- 
> Steven.

More information about the Python-list mailing list