Peter Dimov wrote:
From: "Larry Evans" <[EMAIL PROTECTED]>
1. Find the two X objects (let's call them x1 and x2) on the heap, and
scan
Wouldn't this scan have to be either conservative, like BW, or use some
way
to determine the precise location of the shared_ptr's within, .e.g.
p1->get()?
Currently I use a conservative scan that assumes that shared_ptr instances
have a layout of
T * px;
counted_base * pi;
int id;
with pointers being aligned on a DWORD boundary. 'pi' must be in the count
map, and 'id' must be detail::shared_count::id. (It's possible to test 'px'
for validity too.) False positives should be extremely rare, but could not
be ruled out entirely, and hence, breaking cycles may potentially corrupt
the object.
Would false positives be any less frequent than in the BW conservative collector?
Why not use the Delef approach as demonstrated in shared_cyclic_ptr to avoid
false positives altogether?
This scan will also have to follow plain pointers.
Plain pointers would have to be followed by a real collector, but why should
a "simple cycle-breaker" bother?
Because the following would require it in order to find the cycle:
struc Y;
struct X
{
Y* y; //cyclic involves this arc.
};
struct Y
{
boost::shared_ptr<X> x;
};
int main()
{
boost::shared_ptr<X> p1(new X);
boost::shared_ptr<X> p2(new X);
p1->y.x = p2;
p2->y.x = p1;
}
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost