Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2003-01-29 16:49:18


"Philippe A. Bouchard" <philippeb_at_[hidden]> writes:

>> Have you tried a comparison against a shared_ptr using an optimized
>> count allocator? Nobody has invested as much effort in optimizing
>> shared_ptr as you are pouring into shifted_ptr, but an experiment I
>> did years ago made a huge difference in the efficiency of shared_ptr
>> just by implementing a crude allocator for count objects (took me
>> about 10 minutes to code up). For me to find shifted_ptr convincing
>> I'd have to see a noticeable performance improvement over using an
>> optimized count allocator with shared_ptr.
>
> I think the best way to optimize counts using shared_ptr<> is to
> derive the subject class from counted_base. This way shared_ptr<>
> should logically be exactly like shifted_ptr<> in terms of CPU
> cycles and memory usages. But you won't be able to use typenames
> easily and complex hierarchies will highly likely confront ambiguity
> for multiple ownership if virtual inheritance is not used.
>
> It is just another solution involving different costs / benefits.

That may be the best way to optimize counts using shared_ptr<> if you
don't care about complex hierarchies and "using typenames easily" (not
that I understand what it means). The things you have to give up by
using an intrusive count with shared_ptr are things I care about,
though. AFAICT, the fact that shifted_ptr<> is testing faster than
shared_ptr<> when those features are available is the argument for
shifted_ptr<>'s existence in the first place.

What I'd like to know is whether shifted_ptr still provides any
significant benefits over shared_ptr if you apply a simple
optimization tweak to shared_ptr and use it in its most-flexible
configuration. I don't think it's an unreasonable question, and I'll
need the answer in order to decide whether something like shifted_ptr
is worth accepting into Boost.

-- 
                       David Abrahams
   dave_at_[hidden] * http://www.boost-consulting.com
Boost support, enhancements, training, and commercial distribution

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