Forums | Admin

Discussion Forums: help

Start New Thread Start New Thread

 

By: Paul Brannan
RE: When do you use Address_Registration_Guar [ reply ]  
2008-04-29 14:10
Yes, just the two of us for now.

By: Peter Jaros
RE: When do you use Address_Registration_Guar [ reply ]  
2008-04-29 14:05
Oh, I see. Yeah, a templated ruby_mark() function would be a beautiful solution. In the meantime, I'll use ARG.

Thanks so much for writing Rice, it's making this project a breeze. Is it just you and Jason?

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: Peter Jaros
RE: When do you use Address_Registration_Guar [ reply ]  
2008-04-28 23:26
I get it now. I *do* have a circular reference. Can I write a mark method that will mark the child when the parent is marked and allow the pair to be GC'd when they become unreachable?

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: Peter Jaros
RE: When do you use Address_Registration_Guar [ reply ]  
2008-04-28 20:37
I'm still not sure I follow. If an instance of my class is reachable, will the objects it references be marked?

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.

By: Peter Jaros
When do you use Address_Registration_Guard? [ reply ]  
2008-04-28 20:15
I've got a Data_Type-wrapped C++ class which has a Rice::Array member and a Rice::Object* member. Do I have to make an Address_Registration_Guard for both? Just the pointer? Neither?

Thanks,
Peter