
On Mar 10, 2008, at 6:27 PM, Emil Dotchevski wrote:
On Mon, Mar 10, 2008 at 3:18 PM, Mathias Gaunard <mathias.gaunard@ens-lyon.org> 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. http://www.revergestudios.com/reblog/index.php?n=ReCode