shared_ptr is a reference counting smart pointer in the Boost library. The problem with reference counting is that it cannot dispose of cycles. I am wondering how one would go about solving this in C++. Please no suggestions like: “don’t make cycles”, or “use a weak_ptr”. Edit I don’t like suggestions that say to just […]
How does a reference-counting smart pointer’s reference counting work?
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 instances whose key is the pointer’s address and value is the number of references? If I’ve to implement a shared_ptr, this is the first idea that’s coming to my mind. […]