What’s the performance penalty of weak_ptr?

From the Boost 1.42 source code (<boost/shared_ptr/weak_ptr.hpp> line 155):

shared_ptr<T> lock() const // never throws
{
    return shared_ptr<element_type>( *this, boost::detail::sp_nothrow_tag() );
}

ergo, James McNellis’s comment is correct; it’s the cost of copy-constructing a shared_ptr.

Leave a Comment

tech