On Jun 1, 2006, at 6:47 PM, Joel VanderWerf wrote:

> Lyle Johnson wrote:
>> If you're asking whether Ruby will move the address of the Data  
>> object
>> itself: I'm guessing that that's possible.
>
> If ruby moved objects like that (whether T_DATA or T_OBJECT, T_STRING,
> etc), it would be a disaster. Every VALUE that referred to the object
> (in other words every reference to it in a variable, array, hash,  
> etc.)
> would become invalid, since the VALUE type is actually a pointer in
> these cases. (I may be misunderstanding the question though...)
>
> -- 
>       vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
>

No ruby does not move objects in memory. As to how horrible that  
would be if it did, there are GCs that do work like this (Copying  
GC). Believe it or not there are speed advantages to copying gcs in  
that the algorithm has runtime  proportional to the number of  
reachable objects, rather than the size of the heap like mark-and- 
sweep (which is what ruby uses). Copying collectors also compact the  
the memory, reducing fragmentation. A copying GC would be difficult  
in the current ruby implementation since a copying gc cannot really  
be conservative (it has to change things in the root set), and ruby  
uses the C stack so it is difficult to be sure if something is  
definitely _not_ a pointer. With mark-and-sweep false positives are  
ok, since nothing ever gets moved. With a copying gc it could mistake  
an int on the c stack for a pointer "collect" the "object" it  
"pointed" to and then change the value. Which of course would be the  
cause of many odd and subtle bugs in ruby code.