On Apr 14, 2007, at 09:55, Charles Thornton wrote:

> Does anyone have a chart or text that shows how
> Ruby Memory is used.
> I am trying to work through the Machine translate
> Garbage Collection Chapter.
>
> But I can not translate the text in the diagrams.
>
> It seems to be  Text, Stack, Machine Stack, Heap, ....
>
> Any help here would be appreciated.

I haven't seen these diagrams, but I can describe the memory layout.

Ruby uses the regular C stack for its stack.

Inside the C heap is a pointer to ruby's heap.

Ruby's heap is a C array of pointers to struct heaps_slot.

Each struct heaps_slot consists of a C array of struct RVALUEs.

struct RVALUE is in gc.c, and is some flags and a union of the  
various C object structs.

If a struct RVALUE contains a ruby String, it contains a pointer into  
the C heap with a C char * containing the string contents.  If the  
struct RVALUE is a ruby Array, it contains a pointer into the C heap  
with the C VALUE * holding pointers back to a slot in Ruby's heap.   
(And so-on for the rest of the C object types.)

Also, note that the GC walks the stack looking for pointers into  
ruby's heaps_slots, I'm guessing this is important to the diagram.