Boost logo

Boost :

From: Michael Grundberg (michaelgrundberg_at_[hidden])
Date: 2003-10-24 01:15:04

"Maxim Egorushkin" <e-maxim_at_[hidden]> wrote:
> Looks like you are misusing shared_ptr<>.
> The key point is that shared_ptr<> is an exclusive owner of a raw
> pointer. No more then one shared_ptr<> should be constructed using the

> same raw pointer (unless it is 0 pointer). Violating the rule leads to

> multiple releases on the raw pointer. Using null_deleter allows you to

> remain unpunished :).
> So, as a unique raw pointer has the only associated shared_counters,
> operator<() can be implemented using not a raw pointer but its
> shared_counters.

A while back I read the html page about smart ptr techniques and was
really impressed with all the things one could do with shared_ptr
(Including "Using a shared_ptr to hold a pointer to a statically
allocated object"). But it doesn't say anywhere that shared_ptr should
have exclusive use of a pointer?

But still, assuming that the shared_ptrs are exclusive owners, why is
there need to compare with the shared_counters? The pointers themselves
are equally comparable since they are exclusively owned by the
shared_ptrs. As I see it, the only reason to compare with the
shared_counters is to separate the shared_ptrs when they *don't* have
exclusive ownership of their resources.


Boost list run by bdawes at, gregod at, cpdaniel at, john at