writing code over several lines
Peter Hansen
peter at engcorp.com
Tue Oct 21 18:56:21 EDT 2003
Alex Martelli wrote:
>
> Peter Hansen wrote:
> ...
> > They still have only four bytes (a pointer) per element, and surely for
> > any tuple or list where one could possibly be concerned about memory
> > consumption the number of elements far outweighs the overhead associated
> > with the structure itself (which is probably on the order of a few bytes
> > anyway).
>
> One counterexample from the dark ages:
>
> map(twoargsfunc, lotsoffirstargs, (onesecondarg,)*len(lotsoffirstargs))
>
> the memory consumption of all the constructed tuple's elements is
> fixed -- sizeof(onesecondarg) if Python has sizeof (don't you wish...;-),
> as all slots in the tuple point to that one object.
>
> So, here, the overhead of the structure itself might be important,
> since the elements in that structure aren't; so a tuple MAY be a good
> thing.
Certainly there are cases, such as your example and doubtless others.
"Initializing constant lists at the beginning of the program" likely
isn't one of them, except in exceptional cases.
-Peter
More information about the Python-list
mailing list