How does a reference-counting smart pointer's reference counting work?

后端 未结 7 1080
深忆病人
深忆病人 2020-12-23 21:20

In other words, how does the implementation keeps track of the count?

Is there a map-like object maintained which is accessible by all the shared_ptr in

7条回答
  •  余生分开走
    2020-12-23 21:35

    Each smart pointer object contains a shared reference count - one for every raw pointer.

    You could take a look at this article. This implementation stores these in a separate object which is copied around. You could also take a look at boost's documentation or take a look at the Wikipedia article on smart pointers.

提交回复
热议问题