On 04/13/2016 10:10 AM, Peter Dimov wrote:
Phil,
You still haven't answered my earlier questions, which were
- in what scenarios would one use root_ptr and in what node_ptr, - what happens when one doesn't observe the above guidelines
I think I tried to answer your questions with the following examples: http://philippeb8.github.io/root_ptr/root_ptr/tutorial.html#root_ptr.tutoria...
Perhaps you didn't understand the questions, so I'll go into more detail.
"Root" is GC terminology. It refers to the pointers from which tracing starts (those on the stack, in static variables, in registers.)
So by your calling root_ptr root_ptr, I can deduce that you intend root_ptr to be used for root pointers, and node_ptr to be used for non-root pointers.
Meaning, if we go by classic GC terminology, that automatic and static variables should be root_ptr, and the rest should be node_ptr. Right?
Right but root_ptr can be class members as well (container roots for example).
If that's correct, my question is then what happens when you use node_ptr for roots, and root_ptr for non-roots. That is, what happens when you use node_ptr as an automatic or a static variable (currently a dangling pointer, as we learned in a previous post) and what happens when you use root_ptr for a non-root pointer.
Specifically, in
R1 -> N1 <-> N2
N1 and N2 are destroyed when R1 is destroyed. But what happens in
R1 -> R2 <-> R3
The cycle will not be destroyed there because cycles between sets themselves aren't detected.
or in
R1 -> R2 <-> N3
This cycle will get destroyed. This is because you can have subroots (root pointing to a subroot).
or in
R1 -> N2 <-> R3
when R1 is destroyed?
This cycle will not get destroyed.