[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

GC and the stack

Thomas Sondergaard

10/8/2003 11:07:00 AM

Hello,

As far as I understand the ruby gc will not collect objects that are
referenced from the stack, ie the "C/native" stack in a ruby extension
module.

How does the ruby gc recognize what on the stack is a reference to a ruby
object? The types on and layout of the values in a particular stack frame is
not available at runtime is it?

The initial joy of the simplicity of the ruby C API has for me turned into a
fear of not knowing what is going on concerning especially garbage
collection.

Thomas


4 Answers

nobu.nokada

10/8/2003 11:45:00 AM

0

Hi,

At Wed, 8 Oct 2003 20:08:13 +0900,
Thomas Sondergaard wrote:
> How does the ruby gc recognize what on the stack is a reference to a ruby
> object? The types on and layout of the values in a particular stack frame is
> not available at runtime is it?

By whether a value points an object in the slots. See
gc.c:is_pointer_to_heap().

--
Nobu Nakada

Thomas Sondergaard

10/8/2003 1:21:00 PM

0

> By whether a value points an object in the slots. See
> gc.c:is_pointer_to_heap().

Okay. What if, in an extension, I have an integer on the stack that just
happens to contain a value that interpreted as a pointer points into a valid
point in the heap. Will that prevent the "pointed to" object from being
gc'ed?

Could you outline how the stack is processed? Is it just treated as a
continuous block of memory and scanned for dwords that "point" into the
heap?

Understanding this would be most helpful!

Thank you,

Thomas


Dan Sugalski

10/8/2003 1:48:00 PM

0

Thomas Sondergaard

10/8/2003 2:20:00 PM

0


> Yes. This is normal for conservative garbage collection schemes. (Which
> ruby uses for its stack walking) It's very, *very* rarely an issue.

I believe you. It is just important for me to understand what exactly it
takes to avoid getting reaped by the gc. My question about an integer
variable "pointing" into the ruby heap was not to point out a concern, but
to make sure that I understood it correctly.

So to sum it up: If I am sure that there is a (properly aligned) dword on
the stack that points to my sacred unreapable object it will be safe.

Thanks,

Thomas