From: nobu.nokada@... Date: 2003-10-08T23:29:07+09:00 Subject: Re: GC and the stack Hi, At Wed, 8 Oct 2003 23:09:08 +0900, Thomas Sondergaard wrote: > I have heard statements indicating that you need to declare all local VALUEs > volatile, in order to ensure that they are put on the stack by the compiler > and not in a register. Can I get an authoritative answer to this question? > The ruby source code is full of "volatile", but it is not mentioned once > either on the rubygarden.org WIKI or the README.EXT. Why should this be > necessary? Couldn't the garbage collector check the registers too? Unnecessary, in general. GC checks the registers of course. However, you have to pay attention in this situation. VALUE str = rb_str_new(0, 256); /* make a buffer */ char *ptr = RSTRING(str)->ptr; If str isn't used later, compiler may remove it. And then ptr may be freed when you call ruby APIs and GC runs. StringValue() and StringValuePtr() are provided to avoid this. -- Nobu Nakada