Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #19199 > unrolled thread

Re: access address from object and vice versa

Started byChris Rebert <clp2@rebertia.com>
First post2012-01-21 19:36 -0800
Last post2012-01-23 15:54 +0000
Articles 4 — 4 participants

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: access address from object and vice versa Chris Rebert <clp2@rebertia.com> - 2012-01-21 19:36 -0800
    Re: access address from object and vice versa Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-01-22 05:52 +0000
      Re: access address from object and vice versa Duncan Booth <duncan.booth@invalid.invalid> - 2012-01-23 09:36 +0000
      Re: access address from object and vice versa Grant Edwards <invalid@invalid.invalid> - 2012-01-23 15:54 +0000

#19199 — Re: access address from object and vice versa

FromChris Rebert <clp2@rebertia.com>
Date2012-01-21 19:36 -0800
SubjectRe: access address from object and vice versa
Message-ID<mailman.4917.1327203395.27778.python-list@python.org>
On Sat, Jan 21, 2012 at 7:04 PM, Tamer Higazi <th982a@googlemail.com> wrote:
> Hi people!
> I have asked myself the following thing.
>
> How do I access the address of an object

id(obj) happens to do that in CPython, but it's a mere implementation detail.

> and later get the object from
> that address ?!

Not possible.

> I am heavily interisted.

Why?

Cheers,
Chris

[toc] | [next] | [standalone]


#19206

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2012-01-22 05:52 +0000
Message-ID<4f1ba400$0$29987$c3e8da3$5496439d@news.astraweb.com>
In reply to#19199
On Sat, 21 Jan 2012 19:36:32 -0800, Chris Rebert wrote:

> On Sat, Jan 21, 2012 at 7:04 PM, Tamer Higazi <th982a@googlemail.com>
> wrote:
>> Hi people!
>> I have asked myself the following thing.
>>
>> How do I access the address of an object
> 
> id(obj) happens to do that in CPython, but it's a mere implementation
> detail.

I really wish that CPython didn't expose the fact that id happens to use 
address. That simply gives people the wrong idea.

Jython has the right approach, in my opinion. Objects are given IDs on 
request, starting with 1, and no id is ever re-used:

steve@runes:~$ jython
Jython 2.5.1+ (Release_2_5_1, Aug 4 2010, 07:18:19)
[OpenJDK Client VM (Sun Microsystems Inc.)] on java1.6.0_18
Type "help", "copyright", "credits" or "license" for more information.
>>> id(None)
1
>>> id(True)
2

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.



-- 
Steven

[toc] | [prev] | [next] | [standalone]


#19257

FromDuncan Booth <duncan.booth@invalid.invalid>
Date2012-01-23 09:36 +0000
Message-ID<Xns9FE361B4B2EC3duncanbooth@127.0.0.1>
In reply to#19206
Steven D'Aprano <steve+comp.lang.python@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

[toc] | [prev] | [next] | [standalone]


#19267

FromGrant Edwards <invalid@invalid.invalid>
Date2012-01-23 15:54 +0000
Message-ID<jfjvrs$1vc$2@reader1.panix.com>
In reply to#19206
On 2012-01-22, Steven D'Aprano <steve+comp.lang.python@pearwood.info> wrote:
> On Sat, 21 Jan 2012 19:36:32 -0800, Chris Rebert wrote:
>
>> On Sat, Jan 21, 2012 at 7:04 PM, Tamer Higazi <th982a@googlemail.com>
>> wrote:
>>> Hi people!
>>> I have asked myself the following thing.
>>>
>>> How do I access the address of an object
>> 
>> id(obj) happens to do that in CPython, but it's a mere implementation
>> detail.
>
> I really wish that CPython didn't expose the fact that id happens to use 
> address. That simply gives people the wrong idea.
>
> Jython has the right approach, in my opinion. Objects are given IDs on 
> request, starting with 1, and no id is ever re-used:

But what happens when Jython runs out of numbers?!?!

-- 
Grant Edwards               grant.b.edwards        Yow! I threw up on my
                                  at               window!
                              gmail.com            

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web