Hi, I do know this is very commented subject but I don't understand it clearly:
I'm coding a Ruby C extension which usess Ruby objects (Proc objects,
class instances...) asynchronously, which means that I need to tell CG
not to try those objects until I use them so they can be GC'd.
Could I know which two C functions should I use?:
1) a function for avoiding GC on a given Ruby object (VALUE).
2) a function to re-enable GC on a given Ruby object (VALUE).
There are at least a couple of ways. One is to decalre these objects
as global variables, but that means they will live for the life of the
program (i.e. no GC until the end)
rb_global_variable
Another way is to register the address with GC. I think this is closer
to what you are asking for:
rb_gc_register_address and rb_gc_unregister_address. Note that these
take a pointer to VALUE, not just a VALUE.
HTH,
Ammar
···
On Mon, Apr 16, 2012 at 9:31 PM, Iñaki Baz Castillo <ibc@aliax.net> wrote:
Hi, I do know this is very commented subject but I don't understand it clearly:
I'm coding a Ruby C extension which usess Ruby objects (Proc objects,
class instances...) asynchronously, which means that I need to tell CG
not to try those objects until I use them so they can be GC'd.
Could I know which two C functions should I use?:
1) a function for avoiding GC on a given Ruby object (VALUE).
2) a function to re-enable GC on a given Ruby object (VALUE).
Wouldn't it also work to declare an Array as global variable or
constant and place objects inside until they are no longer needed?
Kind regards
robert
···
On Mon, Apr 16, 2012 at 8:54 PM, Ammar Ali <ammarabuali@gmail.com> wrote:
On Mon, Apr 16, 2012 at 9:31 PM, Iñaki Baz Castillo <ibc@aliax.net> wrote:
I'm coding a Ruby C extension which usess Ruby objects (Proc objects,
class instances...) asynchronously, which means that I need to tell CG
not to try those objects until I use them so they can be GC'd.
Could I know which two C functions should I use?:
1) a function for avoiding GC on a given Ruby object (VALUE).
2) a function to re-enable GC on a given Ruby object (VALUE).
There are at least a couple of ways. One is to decalre these objects
as global variables, but that means they will live for the life of the
program (i.e. no GC until the end)