Boost logo

Boost :

From: Emil Dotchevski (emil_at_[hidden])
Date: 2008-03-11 01:34:03

> On Mar 10, 2008, at 6:27 PM, Emil Dotchevski wrote:
> > On Mon, Mar 10, 2008 at 3:18 PM, Mathias Gaunard
> > <mathias.gaunard_at_[hidden]> wrote:
> >> I see that shared_ptr is quite costly in multithreaded environments
> >> cause it would need DCAS, and thus uses a spinlock in cases where
> >> it is
> >> not available.
> >
> > If you pass shared_ptr objects by const &, the refcount doesn't need
> > to be updated. ... [snip]
> Yes, but be careful that the lifetime of the shared_ptr object passed
> as const & must be guaranteed to outlive the const &, otherwise you
> have a dangling reference.

This is true, but it is also true for any object you pass by
reference. It is even true for the this pointer in a member function.
Regardless, in general, objects of user-defined types are best passed
by const reference; the same is true for shared_ptr.

Emil Dotchevski
Reverge Studios, Inc.

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