How is the std::tr1::shared_ptr implemented?

前端 未结 4 411
忘掉有多难
忘掉有多难 2020-12-02 07:44

I\'ve been thinking about using shared pointers, and I know how to implement one myself--Don\'t want to do it, so I\'m trying std::tr1::shared_ptr,and I have co

4条回答
  •  一向
    一向 (楼主)
    2020-12-02 08:20

    If you want to see all the gory details, you can have a look at the boost shared_ptr implementation:

    https://github.com/boostorg/smart_ptr

    The reference counting seems to usually be implemented with a counter and platform specific atomic increment/decrement instructions or explicit locking with a mutex (see the atomic_count_*.hpp files in the detail namespace).

提交回复
热议问题