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

后端 未结 7 1063
深忆病人
深忆病人 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:31

    As far as I remember, there was the problem of reference counting pointer treated in a chapter of Effective C++.

    In principle, you have the "light" pointer class, containing a pointer to a class holding the reference which knows to increment/decrement reference and destroy the pointer object. That reference counting class points to the object to be referenced.

提交回复
热议问题