Boost logo

Boost :

From: Caleb Epstein (caleb.epstein_at_[hidden])
Date: 2005-11-02 17:29:44

On 11/2/05, Michael D. Crawford <crawford_at_[hidden]> wrote:

0. Am I correct in what I say about the various Boost smart pointers? I
> say shared_ptr isn't thread safe. Am I right? If so, does

No. See Peter's response.

3. Can you pick any nits with my assertions about C++ or the various
> smart pointers? Do you agree with me that the following is a case where
> auto_ptr is the best choice? Can you think of others?

You say in this section that shared_ptr doesn't have a reset() method. It
does. See:
So it would work just as well as auto_ptr in this situation.

There's also a typo in the comment at the top of the sample app:

* ... and scoped_ptr, which permits them
* by using reference counting"

This should be "shared_ptr" not "scoped_ptr" (which you mention first).

Also, I think the example could use some rewriting so it more clearly
illustrates the strengths of the smart pointer approach. I'd suggest
throwing an exception and using a class with a "noisy" ctor/dtor so the user
can see what is happening without using valgrind. I'm attaching a stab at
this to this message.

4. I say early on that neither auto_ptr nor the Boost smart pointers
> provide all the different kinds of smart pointers one would want. What
> other kinds can you think of? How would they be implemented? I already
> have a couple completely implemented, and keep thinking of more, but I'd
> like ideas for others to discuss in my next installment. I won't tell
> you my answers yet because I want to stimulate discussion.

There is a flexible policy-based smart pointer ("policy_ptr") scheduled for
review soon that provides customization options for things like the
reference count implementation, copy semantics, etc. I suspect you've
implemented some similar things.

6. If you were a sinner before you came to my soup kitchen's service,
> have I saved your soul? If not, how could I have made my case more
> effectively? Was your free, hot supper satisfying? Would you come back
> for more?

I'd suggest correcting the factual errors, and linking to some other
resources on smart pointers (e.g. Sutter, Alexandrescu, et al) before I
could say I would walk away from the table feeling full :)

Sutter on auto_ptr:

Alexandrescu on Smart Pointers:

Caleb Epstein
caleb dot epstein at gmail dot com

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