is implemented with id ?

Steven D'Aprano steve+comp.lang.python at pearwood.info
Wed Sep 5 11:36:12 EDT 2012


On Wed, 05 Sep 2012 11:09:30 -0400, Dave Angel wrote:

> On 09/05/2012 10:41 AM, Steven D'Aprano wrote:
[...]
>> So, for current day computers at least, it is reasonable to say that "a
>> is b" implies that a and b are the same object at a single location.
> 
> You're arguing against something i didn't say. I only said that id()
> doesn't promise to be a memory address.  i said nothing about what it
> might mean if the "is" operator considers them the same.

I'm not arguing at all. I'm agreeing with you, but going into more detail.


>> The second half of the question is more complex:
>>
>> "id(a) == id(b)" *only* implies that a and b are the same object at the
>> same location if they exist at the same time. If they don't exist at
>> the same time, then you can't conclude anything.
>>
>>
> But by claiming that id() really means address,

I didn't actually say that. If you re-read Franck Ditter's previous post, 
he doesn't actually say that either.


> and that those addresses
> might move during the lifetime of an object, then the fact that the id()
> functions are not called simultaneously implies that one object might
> move to where the other one used to be before the "move."

Well, yes, but I expect that implementations where objects can move will 
not use memory addresses as IDs. They will do what Jython and IronPython 
do and use arbitrary numbers as IDs.

(Oh how I wish CPython hadn't used memory addresses as IDs.)


> I don't claim to know the jython implementation.  But you're claiming
> that id() means the address of the object, even in jython.

Good god no! I'm saying that, *if* a and b exist at the same time, *and* 
if id(a) == id(b), *then* a and b must be the same object and therefore 
at the same address. That doesn't mean that the ID is the address!


> I think it much more likely that jython uses integer values for the id()
> function, and not physical addresses.

That's exactly what it does. It appears to be a simple counter: each time 
you ask for an object's ID, it gets allocated the next value starting 
from 1, and values are never re-used.



-- 
Steven



More information about the Python-list mailing list