access address from object and vice versa

Duncan Booth duncan.booth at invalid.invalid
Mon Jan 23 04:36:24 EST 2012


Steven D'Aprano <steve+comp.lang.python at pearwood.info> wrote:

> On the other hand, presumably this means that Jython objects need an 
> extra field to store the ID, so the CPython approach is a space 
> optimization.
> 
Given that using `id()` is such an uncommon occurence I would expect the 
ids to be stored outside the object in something like a WeakKeyDictionary.
You can't do that in CPython as some objects aren't weakly referenceable, 
but if you removed that restriction it reduces the overhead.

IronPython & Jython both have garbage collectors that move objects around 
which is why even if you could get at the address it wouldn't be much use 
as it may change at any time.

-- 
Duncan Booth http://kupuguy.blogspot.com



More information about the Python-list mailing list