The REALLY bad thing about Python lists ..

Courageous jkraska1 at san.rr.com
Tue May 16 07:47:32 CEST 2000


> Python deliberately overallocates by a small amount; this is a deliberate
> optimization for the cases Moshe identified; it works very well.

BTW, for those who are interested, but don't have the time to
look, here is the actual behavior:

#define ROUNDUP(n, PyTryBlock) \
	((((n)+(PyTryBlock)-1)/(PyTryBlock))*(PyTryBlock))

static int roundupsize(n)
	int n;
{
	if (n < 500) return ROUNDUP(n, 10);
	else return ROUNDUP(n, 100);
}

I'm curious, looking at this, why we're not able to access
the initial sizes and growth rates directly? While such
needs are rare, and therefore shouldn't be added syntatic
weight for the everyday user, I'd think there would be
some benefit in allowing the complexity fiends some level
of access with relatively little cost (is the extra overhead
of keeping a growth rate attribute on the vector structure
a burden? come now).


C/



More information about the Python-list mailing list