This is a follow up to my thread last week regarding using Swig to
create Ruby libraries and intermingling Ruby and C data types.
What I'm looking to do is to mark Ruby objects that are passed down to
the C libraries so that they're not garbage collected. I've verified
that C can hold a reference to a Ruby object easily enough. But,
unfortunately, once the Ruby object is handed off it's getting GC'd
since Ruby doesn't see anything holding a reference to it.
Looking at Data_Wrap_Struct it mentions the mark method but I can't find
any examples of what such a method would do.
Looking at Data_Wrap_Struct it mentions the mark method but I can't find
any examples of what such a method would do.
Looking at the Ruby source, I see an example in marshal.c. The mark
method is mark_marshal_compat_t. I looked at my code archive: it seems
I used the mark method only once. Basically, in it you call rb_gc_mark
on all those ruby objects that you do not want to be reaped. That's
all, it seems.
Carlo
···
Subject: How to mark an object so it is not garbage collected
Date: Mon 26 Jan 15 01:48:47PM -0500
--
* Se la Strada e la sua Virtu' non fossero state messe da parte,
* K * Carlo E. Prelz - fluido@fluido.as che bisogno ci sarebbe
* di parlare tanto di amore e di rettitudine? (Chuang-Tzu)
Hrm, then how would Ruby know that the state of the object has changed
at some later point?
···
On Mon, Jan 26, 2015 at 08:13:38PM +0100, Carlo E. Prelz wrote:
Subject: How to mark an object so it is not garbage collected
Date: Mon 26 Jan 15 01:48:47PM -0500
Quoting Darryl L. Pierce (mcpierce@gmail.com):
> Looking at Data_Wrap_Struct it mentions the mark method but I can't find
> any examples of what such a method would do.
Looking at the Ruby source, I see an example in marshal.c. The mark
method is mark_marshal_compat_t. I looked at my code archive: it seems
I used the mark method only once. Basically, in it you call rb_gc_mark
on all those ruby objects that you do not want to be reaped. That's
all, it seems.
--
Darryl L. Pierce <mcpierce@gmail.com>
Famous last words:
"I wonder what happens if we do it this way?"
NM, I see that the mark function is called at the beginning of a GC path
to mark any object that should not be reaped. So there isn't any
inverse to it.
Now to just find a way to integrate that with Swig and I'll be good to
go.
···
On Mon, Jan 26, 2015 at 02:48:56PM -0500, Darryl L. Pierce wrote:
On Mon, Jan 26, 2015 at 08:13:38PM +0100, Carlo E. Prelz wrote:
> Subject: How to mark an object so it is not garbage collected
> Date: Mon 26 Jan 15 01:48:47PM -0500
>
> Quoting Darryl L. Pierce (mcpierce@gmail.com):
>
> > Looking at Data_Wrap_Struct it mentions the mark method but I can't find
> > any examples of what such a method would do.
>
> Looking at the Ruby source, I see an example in marshal.c. The mark
> method is mark_marshal_compat_t. I looked at my code archive: it seems
> I used the mark method only once. Basically, in it you call rb_gc_mark
> on all those ruby objects that you do not want to be reaped. That's
> all, it seems.
Hrm, then how would Ruby know that the state of the object has changed
at some later point?
--
Darryl L. Pierce <mcpierce@gmail.com>
Famous last words:
"I wonder what happens if we do it this way?"