From: Simon Strandgaard <0bz63fz3m1qt3001@...> Date: 2003-06-27T05:18:31+09:00 Subject: Re: collect info about ruby-api On Thu, 26 Jun 2003 12:17:14 +0200, Tobias Peters wrote: > 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. Yes I know mark&sweep GC. > Your two methods would declare your variables global. Yes. I know there is other methods. The reason why I suggested these 2 methods is because I want to avoid confusing people.. No one would have understod me if I had presented all posible methods. These 2 methods represent the only two distinct ways you can tell GC that there is a new instance in town. #1 export a C variable into Ruby. #2 non-export.. not visible within Ruby. I have no insigth in what Init_stack does.. I am guessing it belongs to the second category? > 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. I don't know anything about Ruby + stack... tell me more ? It is not because I don't know what a stack is.. I have done assembler programming, written compiler, cpu emulator, operating system... I think I know what a stack is :-) I just don't understand the purpose+goal with Init_stack. >> >> 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: [snip code] > 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. I don't see where Init_stack enters the picture ? > If you can't believe this, then learn about it yourself: I already know what a stack is.. > 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. I have not read 'gc.c' closely.. I know mark&sweep. I don't know much about Ruby's internals (NODE ???). I am still curious.. * what can Init_stack be used for? * when is it supposed to be used? * any 'short' example of usage? Im listening :-) -- Simon Strandgaard