The REALLY bad thing about Python lists ..

Andrew Dalke dalke at acm.org
Tue May 16 13:42:43 EDT 2000


Courageous:
>Well, to be honest, I was more surprised at the implementation
>itself; ever since I can remember, I've never seen an allocation
>in advance vector without it storing its own growth rate........

Where's the access for STL's vector?  Looking at
 http://www.sgi.com/Technology/STL/Vector.html
it looks like there's no way to change the "usually increases it
by a factor of two" to some other value.

(And yes, it does say """It is crucial that the amount of growth is
proportional to the current capacity(), rather than a fixed constant:
in the former case inserting a series of elements into a vector is a
linear time operation, and in the latter case it is quadratic.""" :)

>BTW, I missed what you meant by your generators comment. I fail
>to see how this would be necessary if every list per se had a
>growth_rate element attribute, although you'd think the more
>necessary thing would be the initial size hint, actually. Albeit,
>perhaps as the other poster noted, the realloc is making it
>cheap most of the time.


Sorry.  My fault for writing the post just before falling asleep.
(You can tell because I wrote "either" with only one clause :)
You wanted the ability to chang the initial size hint and the growth
rate.  There are three places to do this:
  1) change global variables which decide these values,
  2) pass them into the constructor for a list, like [](init, rescale)
(which isn't legal, but I can't think of good syntax).
  3) change them on a per-object basis.

The first isn't good because you could have two libraries, both
of which want to change the values.  The second is the one I would
prefer, if I had to, but it requires a syntax which Python doesn't
support.  The final one requires new accessors for the rescale, and
doesn't allow pre-allocation.  This, I believe, it what you prefer.

I note that C++ does allow pre-allocation, but not access to the
rescale value.

Regard the comment about threads as spurious, sleep-induced nonsense.

                    Andrew
                    dalke at acm.org






More information about the Python-list mailing list