Boost logo

Boost :

From: David B. Held (dheld_at_[hidden])
Date: 2002-03-21 15:12:18


----- Original Message -----
From: "E. Gladyshev" <egladysh_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Thursday, March 21, 2002 11:41 AM
Subject: RE: RE: [boost] shared_prt, will it crash?

> [...]
> The fool() function could be a generic function
> that is called from different contexts.
>
> fool() is very dumn and doesn't want to learn
> anything about memory allocation tricks.
> Fortunately fool() knows a very smart guy, named
> shared_ptr<>,... but is he really smart?

The thing is that shared_ptr *assumes ownership
of the data*. When you create a smart pointer
from a raw pointer, you are saying: "I want this
smart pointer to take control of when this object
gets destructed." If you cannot guarantee that
*you* have ownership of the data in question, then
you have no authority to pass that ownership on to
a smart pointer. Only use shared_ptr when you
can guarantee that you indeed have ownership
of the data, and are allowed to call delete on it.

Dave


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