[Python-Dev] sizeof(long) != sizeof(void*)
Tim Peters
tim.one at comcast.net
Wed Aug 6 22:23:02 EDT 2003
[Samuele Pedroni]
> care to suggest a cheap way to get such a unique integer that's
> not the address.
I'd love to, but don't know enough about Java to guess.
> ...
> otherwise I see no other way than keeping a weak identity mapping
> from objects to integral type values, the aforementioned unique
> integers.
Then is there a reason not to do that? Presumably only objects to which
id() is actually applied need to become keys in such a mapping, and if so
only id() users pay the price.
> Likely using a type for which a counter to get fresh unique
> integers cheaply will not overflow too quickly.
If it's a weak-keyed dict you could also reuse the integer values associated
with keys that go away.
> Or instead of the mapping attach such integrals value to each
> object. The latter is not an option for Jython, because we cannot
> attach things to general Java objects we have to deal with.
Then why bring it up <wink>?
Note that I don't object to introducing a mechanism that copy etc can use
that's highly efficient under all implementations. But the introduction of
such a mechanism isn't sufficient reason to get rid of the current id(),
even if id() is horridly expensive in some implementations.
More information about the Python-Dev
mailing list