Protect objects of a C extension from GC

D

Detlef Reichl

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
 
T

Tim Hunter

Detlef said:
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.
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top