List size versus list allocation

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sun May 2 10:57:30 EDT 2010


Python lists are over-allocated: whenever they need to be resized, they 
are made a little bit larger than necessary so that appends will be fast.

See:

http://code.python.org/hg/trunk/file/e9d930f8b8ff/Objects/listobject.c

I'm interested in gathering some statistics on this, and to do so I need 
a way of measuring the list's logical size versus its actual size. The 
first is easy: it's just len(list). Is there some way of getting the 
allocated size of the list?



-- 
Steven



More information about the Python-list mailing list