What does Python fix?
François Pinard
pinard at iro.umontreal.ca
Mon Jan 21 10:14:52 EST 2002
[Alex Martelli]
> > In Lisp, there is the capability of having genuine pointers all along a
> > single list. There is probably no memory-efficient equivalent in Python.
> I don't know what "genuine pointers" are in this context (as opposed to
> Python references). Do you mean pointers subject to address-arithmetic,
> as in C?
I meant that, given a tuple (a, b, c, d) or a list [a, b, c, d], you can
only save a reference to the whole object starting on the first element.
You may not reference the (b, c, d) part without having a new object with
this contents; there is no memory sharing, at least so far that I know.
> In any case, if for some given application you think cons cells are
> the way to go, they're easy to make in Python. I've chosen them as
> an extension example, but they really work well in pure Python too.
> See http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66509 ...
Someone might use the equivalent of cons-cells, with this representation:
(a, (b, (c, (d, ()))))
Of course, I had this in mind while writing the original message. When I
say that there is probably no memory-efficient equivalent in Python, I am
guessing that each 2-tuple is probably much more costly than the mere pair
of memory words that would be needed for the same thing, in Lisp.
I much agree that all these considerations are a bit of rhetorical exercise,
as in real practice, for the examples being discussed, neither the space
or time consumed in Python is worth the worry. On the other hand, a better
understanding of things might yield better abilities to choose the correct
representation, for when the time come to address bigger applications.
--
François Pinard http://www.iro.umontreal.ca/~pinard
More information about the Python-list
mailing list