Memory overhead for trees?

François Pinard pinard at iro.umontreal.ca
Fri Aug 16 00:42:30 CEST 2002


Hi, people.

I'm toying with the idea of converting an existing LISP system into Python.
The system uses a lot of real trees, I mean, more deep than wide on average.
Trees are traversed and explored a great deal, but modified relatively less
often.  I'm seeking a representation which, while being reasonably efficient
-- yet no miracles are expected here! -- is not too voracious on memory.

Do you know how worth the memory savings of using tuples over lists?
I'm tempted to guess that the savings are not worth all the trouble it
would take to convert between both when the need of modification arises.

I've the feeling, too, that sub-classing tuples or lists (only possible in
recent Python versions) is significantly more economical in memory than
using traditional classes, while keeping the application in closer touch
with the built-in speed of the tuple or list implementation.  Moreover,
that would allow using the sub-classed types in a wider range of Python
contexts where built-in tuples or lists are directly usable.

Could I hope that sub-classing tuples or lists could be done with only
little, or maybe no extra memory cost, compared to using tuples or lists
directly?  Surely, the idea of sub-classing is very attractive, from the
comfort resulting from possible specialised methods over the built-ins.

In a word, your comments are welcome! :-)

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard





More information about the Python-list mailing list