Boost logo

Boost Users :

Subject: Re: [Boost-users] [smart_ptr]intrusive_ptr suggestion
From: gast128 (gast128_at_[hidden])
Date: 2010-08-12 10:56:32


Andrew Holden <aholden <at> charteroaksystems.com> writes:

>
> On August 11, 2010 5:35 PM, gast128 wrote:
> > <snip>
> >
> >> Perhaps you should initialize the reference count to zero in the
> >> constructor of IFoo, instead of initializing it to 1.
> >>
> >> In Christ,
> >> Steven Watanabe
> >
> > Yes but I think it is more natural that the ref count starts at 1 for a
ref counted object. Thats at least the
> COM protocol
>
> It's a slightly different situation. COM is designed for manual reference
counting. It assumes that each
> raw pointer, including the one returned from the constructor, counts as a
reference. For boost intrusive
> pointers, the count is the number of intrusive pointers referencing the
object. Until you assign the
> object to one, that count is zero.

Not sure if this adresses my problem. intrusive_ptr is used in situations
where the object or some other mechanism keeps tracking of its lifetime.
intrusive_ptr only guarantees to call 'intrusive_ptr_add_ref'
and 'intrusive_ptr_release' on construction and destruction of the
intrusive_ptr. The most used scenario is probably objects which are ref
counted. The count doesn't need to be the number of intrusive_ptr's on the
object; it can be larger than that.

Objects which start with a ref count of 1 get the previously described
problem. Afaik is that also the most used scenario. Objects with reference
count of 0 shouldnt be alive.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net