What's the performance penalty of weak_ptr?

后端 未结 3 527
耶瑟儿~
耶瑟儿~ 2021-01-03 18:53

I\'m currently designing a object structure for a game, and the most natural organization in my case became a tree. Being a great fan of smart pointers I use shared_pt

3条回答
  •  隐瞒了意图╮
    2021-01-03 19:58

    From the Boost 1.42 source code ( line 155):

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

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

提交回复
热议问题