|
Boost : |
From: George A. Heintzelman (georgeh_at_[hidden])
Date: 2002-01-18 15:52:01
Peter Dimov wrote:
> George Heintzelman wrote:
> > I don't like adding the extra layer of indirection for *all* shared_ptr
> > destructor calls, in order to 'solve' this, for the destructor case
> > only. In a policy-based smart pointer, I would support making it an
> > available policy but not the default one.
>
> I'd be surprised if you could measure the added cost. Besides, the extra
> layer of indirection has other good uses. It makes it possible to pass
> shared_ptr<>s across exe/dll boundaries (that use different heaps.)
Most times I'm sure you're right. I'm mostly concerned with the cases
where the cases where the data members of the pointed-to object are all
simple types, requiring no destructor calls, or ones with similarly
simple inline destructors; then the C++ implementation can completely
optimize away function calls except for the deallocation. I suspect
that the layer of indirection here will make it much more unlikely for
compilers to perform that optimization.
With shared_ptr's being a commonly recommended way for dynamically
storing things in vectors without copying the data, I think this may
occur fairly often. Just looking over my personal code, I have several
examples of such vectors. It just seems a violation of the
no-use-no-pay rule.
George Heintzelman
georgeh_at_[hidden]
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk