writing code over several lines

Peter Hansen peter at engcorp.com
Tue Oct 21 15:33:58 EDT 2003


Emile van Sebille wrote:
> 
> "Peter Hansen"
> > Is there a published algorithm behind this, or is it just some magic
> > of the Timbot's that would be found only in the source?
> >
> 
> Both  ;-)
> 
> From cvs listobject.c...
> 
>  /* Round up:
>   * If n <       256, to a multiple of        8.

Thanks, Emile; Paul was right...

So the above is probably the extent of the damage.  In the example
given, that would mean instead of (9*3+9)*4 or 144 bytes from the 
element pointers, (9*8+16)*4 or 352 bytes would be consumed instead.
My guess is that this amount is about on par with the overhead 
associated with the rest of the objects involved, such as the memory 
consumed by the list object itself or by the integer objects.

Given how many such "constant lists" one creates in an average program 
and how insignificant these numbers really are compared to almost any
aspect of Python, such as the overhead of the .pyc in memory, I 
wouldn't think this aspect should concern most Python programmers...

Now, if the items in question were triplets of numbers of some kind,
such as coordinates, then I'd agree the nine elements should be tuples
themselves, but the containing thing should still be a list, merely
for readability and consistency with conventional style.

Not that any of this amounts to a hill of beans in the greater
scheme of things....

-Peter




More information about the Python-list mailing list