|
Boost : |
From: Dave Harris (brangdon_at_[hidden])
Date: 2002-06-19 17:28:22
In-Reply-To: <aeoir4$lu4$1_at_[hidden]>
On Tue, 18 Jun 2002 19:24:10 -0500 David B. Held
(dheld_at_[hidden]) wrote:
> [intrusive versus non-intrusive shared_ptr]
> What were the problems?
The main issue was the lack of a safe way to get a counted pointer from a
raw pointer. It's not a problem if you can avoid raw pointers everywhere,
but that isn't always feasible. In particular, "this" is a raw pointer and
there was no good way for an object to get a counted pointer to itself.
Eg you couldn't say:
void Item::append_to( Container &c ) {
c.push_back( shared_ptr( this ) );
}
because this would create a new reference count each time it was called.
A second issue is efficiency. Intrusive pointers can be more efficient to
create as they don't need extra memory allocations for the count.
The advantage of non-intrusive pointers is that they can point to
anything. The current design is a hybrid intended to give the best of both
worlds.
There are also some issues over whether smart pointers should be
policy-based, and if so how those policies should be specified for
concrete uses. As far as I know, the boost community itself is not yet
decided about this, let alone the standards committee.
-- Dave Harris
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk