Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-11-26 07:39:15


From: "Jim Grandy" <jgrandy_at_[hidden]>
> From: "Peter Dimov" <pdimov_at_[hidden]>
[...]
> > OK, here is the one-line solution:
> >
> > template<class T> intrusive_ptr<T> dont_addref(T * p)
> > {
> > intrusive_ptr<T> pt(p);
> > intrusive_ptr_release(p);
> > return pt;
> > }
>
> I'm not sure this addresses the efficiency concern I raised earlier. You
> still incur an extra addref and release call inside your C++ wrapper
> interface for every API call, which can easily be an unacceptable
> performance hit. Since intrusive_ptr is hermetically sealed, there is no
way
> around the unnecessary two calls (short of adding a constructor).

No, it doesn't address the efficiency concern. This is intentional. I
believe that efficiency is not a legitimate concern in this case. The API
calls will incur much more overhead than an extra 'release'... unless they
do something trivial. I'd expect 'CopyMenuTitle' to be at least one order of
magnitude slower than Release.

If you can demonstrate, with real data, that the efficiency concern is
legitimate, I will certainly consider your 'dont_addref' suggestion...
although in such a situation I'd refrain from using a smart pointer at all,
as it's too easy to copy inadvertently (which is addref/release, i.e. twice
as expensive as an extra release alone.)


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