Forum: Ruby Protect objects of a C extension from GC

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Detlef R. (Guest)
on 2007-07-29 16:44
(Received via mailing list)
Hi,

I'm writing on a video procession system. In this i have a C extension,
which creates ruby objects that encapsulate images. This objects are
passed with some ruby code to an other C extension which shall store
them for later output.

My problem is, that the GC destroys the objects while they are needed in
the future. I've tried to prevent this by calling

  rb_gc_register_address (&myobject);

on the object and after i'm done with the object

  rb_gc_unregister_address (&myobject);

But that seems to be ignorred.


Any hints about this?


TIA
detlef
Tim H. (Guest)
on 2007-07-29 19:23
(Received via mailing list)
Detlef R. wrote:
>   rb_gc_register_address (&myobject);
>
> on the object and after i'm done with the object
>
>   rb_gc_unregister_address (&myobject);
>
> But that seems to be ignorred.
>
Are you creating the objects using the Data_Make/Wrap/Get_Struct macros?
If so, establish a mark routine that GC can call so you can mark your
objects as being still in use by calling the rb_gc_mark function. See
Chapter 21 in the Pickaxe.
This topic is locked and can not be replied to.