Boost logo

Boost :

From: Ed Brey (brey_at_[hidden])
Date: 2002-07-19 08:31:35


"Peter Dimov" <pdimov_at_[hidden]> wrote in message news:004c01c22f0b$bc8d0760$1d00a8c0_at_pdimov2...
>
> This comes at a cost. counted_base::release() const implies
> counted_base::dispose() const. The function that dispose() performs is to
> release any resources managed by the object. Hence, these resources would
> need to be made mutable, and const correctness goes MIA.

Why is dispose() used to release resources, rather than the destructor? It would be nice to not have dispose(), so that classes that faithfully clean up via their distructors don't have to pay for dispose() (fortunately, it's quite minimal, anyway).

> The "other" counted_base can be defined by the user, since there is nothing
> special about it. It would be convenient to have it, of course, if there is
> demand for a standard counted base with const addref/release methods.
>
> > What's your plan for gathering enough information to make a decision on
> how to proceed?
>
> My "highly scientific" plan is:
>
> 1. Replace all of my intrusively counted pointers with
> boost::intrusive_ptr<>. See if any problems surface (none so far; I've no
> need of intrusive_ptr<T const>.)
>
> 2. Wait for feedback from intrusive_ptr users (if there are any.)

By way of comparison, and to demonstrate another usage pattern, I'll describe here the steps that I went through regarding intrusive_ptr. Perhaps this will demonstrate that it is likely that const addref/release methods will be widely desired.

1. I saw discussion on boost about intrusive_ptr.

2. I looked at the code and noticed that it has a leaner pointer and saves a heap allocation.

3. I added counted_base as a base class to those classes that had typically been held by shared_ptr before, and converted the shared_ptrs to intrusive_ptr.

4. I was happy, except for the cases where I my new code had intrusive_ptr<T const>. So I changed those to back shared_ptr. I also noticed that given T const, shared_ptr silently pessimized by not using counted_base, so I removed the counted_base from the shared class's bases, since it was doing no good.

5. I posted to boost, with the ultimate hope of making dealing with intrusive reference counting more flexible and transparent.


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