[Python-Dev] gc ideas -- sparse memory

"Martin v. Löwis" martin at v.loewis.de
Sat Dec 4 09:59:08 CET 2010


> I'm afraid I don't follow you. Unless you're suggesting some sort of
> esoteric object system whereby objects *don't* have identity (e.g. where
> objects are emergent properties of some sort of distributed,
> non-localised "information"), any object naturally has an identity --
> itself.

Not in Java or C#. It is in these languages possible to determine
whether to references refer to the same object. However, objects don't
naturally have a distinct identification (be it an integer or something
else).

If you really want to associate unique numbers with objects in these
languages, the common approach is to put them into an identity
dictionary as keys.

> It seems counter-productive to me to bother with an identity function
> which doesn't meet that constraint. If id(x) == id(y) implies nothing
> about x and y (they may, or may not, be the same object) then what's the
> point?

See James' explanation: it would be possible to use this as the
foundation of an identity hash table.

> Why would you bother using that function when you could just use
> x == y instead?

Because in a hash table, you also need a hash value.

Regards,
Martn


More information about the Python-Dev mailing list