From: Tobias Peters Date: 2003-06-26T18:52:56+09:00 Subject: Re: collect info about ruby-api On Wed, 25 Jun 2003, Simon Strandgaard wrote: > On Wed, 25 Jun 2003 22:57:53 +0900, nobu.nokad wrote: > > > #3 Init_stack(address) > > tell GC the machine stack limit. > > I never heard about this before, what does it do ? > Can you give me a more lengthy description of it :-) > Simon, remember how the GC works: Every time it runs, it marks all objects that are still reachable, from either global variables, or from local variables that are currently somewhere on the execution stack. Your two methods would declare your variables global. Nobu's suggested to rely on the fact that objects currently referenced from local variables also get marked. Local variables are references that live on the stack. The Init_stack method corrects ruby's idea of where the C stack starts. All objects referenced from the C stack will be marked during a GC run. > > > grep Init_stack *.h > > > > It doesn't seems to something public available to the embedding/extension > Rubyist's. To me it looks like an internal routine. It will be called from ruby_init. You can avoid calling it explicitly if you do all your work from within another function after you called ruby_init, like this: main(int argc, char * argv[]){ ruby_init(); do_the_work(argc, argv); } do_the_work(int argc, char * argv[]){ VALUE x1 = ... VALUE x2 = ... ... } Then you can _RELY_ on the fact that _none_ of your objects pointed to by x1, x2, etc, will be destroyed _before_ the do_the_work function returns. No need to register objects as globals! If you can't believe this, then learn about it yourself: You have to have an understanding of how the C stack is generally used for function call parameters and local variables. Maybe http://www.codeproject.com/tips/stackdumper.asp, section 1.1 can serve as an introduction. And you need an idea of how the garbage collector works. The C code in the file "gc.c" is very readable, if you ignore all the switch/case branches that mention some NODE objects. Tobias