Memory pre-allocation for large lists

Erik Max Francis max at alcyone.com
Wed Feb 18 02:36:52 EST 2004


Aahz wrote:

> Can, yes.  But why?  Python uses an allocation mechanism for lists
> that
> results in constant amortized time; there's really no reason to
> pre-allocate.

If you know the size of the (large) array in advance, it's completely
legitimate to preallocate the array to make the constant time factor.

-- 
 __ Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
/  \ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
\__/ Even paranoids have real enemies.
    -- Delmore Schwartz



More information about the Python-list mailing list