Boost logo

Boost :

From: Schoenborn, Oliver (Oliver.Schoenborn_at_[hidden])
Date: 2003-05-28 11:03:43

> -----Original Message-----
> From: Larry Evans [mailto:jcampbell3_at_[hidden]]
> Sent: Wednesday, May 28, 2003 7:29 AM
> To: Boost mailing list
> Subject: [boost] Re: smart_ptr suggestion: Support decrementing
> shared_ptr'scount,forself-references
> Schoenborn, Oliver wrote:
> > Circular refs are easy to avoid with smart_ptr lib but
> idiomatically what
> > you are really looking for is DynObj (and maybe RRef ) in
> the NoPtr lib
> > ( Strict ownership is
> ideal for pimpl and
> > in particular your example of circular dependency, as
> supported by the NoPtr
> > lib.

> This sounds like the polaris' RefWrapper (similar to boost
> weak_ptr) and
> Wrapper (similar to your NoPtr) class.

Interesting, thanks for info, I'll have to take a look.

> However, a cycle can still be formed even with single ownership. A
> pointee can contain a Wrapper which points to itself.

Yes, it's a cycle but not the kind that leads to the problem found with
shared ownership, where two owners can't do their job properly because one
is indirectly self-refering, screwing up the ref count and leading to the
object not being deleted (or deleted twice). With strict ownership the cycle
is outright misuse of ownership, as is possible with shared_ptr even if
cyclic ref count were NOT possible:

struct Foo {
   DynObj<Foo> foo;
   // owns the object pointed by pfoo
   void reset(Foo* pfoo) { foo.acquire(pfoo);}

DynObj<Foo> foo2(new Foo);
foo2().reset( foo2.release() ); // ok
foo2().reset( foo2.getPtr() ); // ouch, reset takes ownership!!

This is not a reference count problem, it's outright wrong, just like doing

Foo foo0; // not a pointer: auto variable
shared_ptr<Foo> foo( & foo0 ); // boom somewhere down the road!

is outright wrong but will be silently accepted by compiler. Do you have an
example of the case you had in mind in your reply?


Boost list run by bdawes at, gregod at, cpdaniel at, john at