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

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

    No. shared_ptr just keep one additional pointer for reference counting.

    When you make copy of shared_ptr object it copy pointer with count of references, increase it, and copy pointer on contained object.

提交回复
热议问题