 |
Forums |
Admin Discussion Forums: help Start New Thread
By: Paul Brannan
RE: When do you use Address_Registration_Guar [ reply ] 2008-04-29 13:21
|
Yes, you can write a mark function, but it's not as easy as it should be:
void my_mark(My_Type * foo) { ... }
...
Data_Object<My_Type> obj(
new My_Type,
rb_cMyType,
my_mark);
Unfortunately this mark function only applies to this object. I think I can fix the default mark function so you would only need to specialize a template:
template<>
void ruby_mark(My_Type * obj) { ... }
I'll try to have this in the next version of Rice.
|
By: Paul Brannan
RE: When do you use Address_Registration_Guar [ reply ] 2008-04-28 20:45
|
If you pass an address (pointer) to the constructor of an Address_Registration_Guard, it will ensure that rb_gc_mark(*address) will always be called when the mark phase of the GC is entered, until the guard is destroyed.
In other words, as long as the guard is alive, the child (*address) will not be destroyed.
If the child refers back to the object containing the Address_Registration_Guard, the guard will never be destroyed, and neither with the parent nor child object.
|
By: Paul Brannan
RE: When do you use Address_Registration_Guar [ reply ] 2008-04-28 20:21
|
|
You can use the Address_Registration_Guard as an alternative to writing a mark function for your class. I believe it can be used any time you can ensure there are no circular references between your object and its members. Using an Address_Registration_Guard is the same as calling rb_gc_register_address/rb_gc_unregister_address in C.
|
|
 |