writing code over several lines
Alex Martelli
aleaxit at yahoo.com
Tue Oct 21 18:33:56 EDT 2003
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.
Today we do [twoargsfunc(x,onesecondarg) for x in lotsoffirstargs]
and we don't worry much about huge tuples made all of the same
element any more;-). But there may still be a few such cases around.
Alex
More information about the Python-list
mailing list