SpringFlowers AutumnMoon wrote:
> Rick Denatale wrote:
>> On 9/24/07, Tim Hunter <TimHunter / nc.rr.com> wrote:
>>> > so the question is...  which objects have the object_id 2, 4, 6, and -2,
>>> irb(main):004:0> x.object_id
>>> => 0
>>> irb(main):005:0> x = nil
>>> => nil
>>> irb(main):006:0> x.object_id
>>> => 4
> 
>> One should keep in mind that these are interesting implementation
>> artifacts.  I don't believe that there's any guarantee that such ids
>> would be the same in an arbitrary ruby implementation or even between
>> versions of the same implementation.
> 
> right, it is just from the curiosity standpoint.  that where did those 
> even number object id's go?   (the 10002, 10004, etc)

Object ids are memory addresses. Due to the way C programs (remember 
Ruby is a C  program) allocate memory, the object ids that are not 
Fixnums and not very small even numbers are (at least in common systems) 
always multiples of 8, so 10002 isn't going to be a real object id. 
Also, because of the way operating systems dole out memory to C 
programs, the memory addresses are usually going to be very large 
numbers. (Mostly because operating systems like to reserve low memory 
addresses for themselves.) Memory addresses are of course always 
positive numbers, but Ruby displays object ids as signed numbers. If the 
memory address is sufficiently large (such that the sign bit is set) 
Ruby displays it as a negative number.

Of course at this point somebody will pipe up and say that what I just 
wrote is untrue on such-and-such an obscure computer, and they'd be 
right. I'm just talking about the kind of computers (PCs) and operating 
systems (Win, Linux, etc.) that Ruby commonly runs on. Personally I'd be 
interested in hearing about computers that Ruby runs on that don't act 
this way.
-- 
Posted via http://www.ruby-forum.com/.