Boost logo

Boost :

From: Greg Colvin (gcolvin_at_[hidden])
Date: 2001-05-29 09:02:26


From: Beman Dawes <bdawes_at_[hidden]>
> At 07:09 PM 5/26/2001, Greg Colvin wrote:
>
> >At this point cyclic_ptr is a toy...
> >
> >...
> >
> >My cyclic_ptr is an experiment in combining reference counting
> >and mark-sweep to get some of the advantages of each, but it
> >is too soon to say how successful it is.
> >
> >...
>
> Why is it a toy? Because the design and implementation are incomplete, or
> because it has not been thoroughly tested, exposed to public comment, and
> widely used?

Mostly the latter (testing, comment and use). The Boehm and
Great Circle collectors have been in widespread use for years
now.

There are also a lot of design tradeoffs -- witness the three
or four I have published or proposed over the years, the four or
five garbage collectors now in the Boost vault, and the many
others in the literature and on the web.

Finally, it gets around C++'s lack of metadata by a clever hack
with a static variable and cyclic_ptr::operator=(), which hack
can be fooled by a common way of writing operator=(). So the
following is wrong:

   struct X {
      cyclic_ptr<Y> p;
      ...
      X& operator=(const X& x) {
         if (&x != this) {
            p = x.p;
            ...
         }
         return *this;
      }
   };

The above will prevent the collector from tracing through X::p.
Instead you must write something like this:

   struct X {
      cyclic_ptr<Y> p;
      ...
      X& operator=(const X& x) {
         p = x.p;
         if (&x != this) {
          ...
         }
         return *this;
      }
   };

Subtle, and at least one Booster has been burned by it.
         
> Put another way, what do we have to do to mature it to the point where we
> can make a final keep/abandon decision?

Decide whether we can live with the design tradeoffs and the
hack. I'd feel better about the hack if there was a better
way to do it coming in the next version of C++.

Also, decide whether being able to collect cycles is all that
important. We have gotten by with acyclic reference counting
pretty well.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk