[Smart Pointer] Reference counting when you don't want to manage memory [Honeywell Internal]

Classification: Honeywell Internal Smart pointers (as in http://www.boost.org/doc/libs/1_56_0/libs/smart_ptr/smart_ptr.htm ) assume that the action you want to perform when the count goes to zero is to free the memory pointed to. That isn't the only use for reference counting. Why doesn't the Smart Pointer library decouple the reference counting from the action to be taken and provide a generic reference counting mechanism that will call an arbitrary function when the count goes to zero? The default can be "delete" to provide the expected memory management capability but it would provide a robust mechanism for those who need other capabilities. Reviewing the <boost/shared_ptr.hpp> code, it appears this decoupling already exists - through the use of boost::checked_delete and boost::checked_deleter (<boost/checked_delete.hpp>). It just doesn't appear to be documented. Why not document this so others know how to use it? Steve Hickman System Architect, Flight Deck of the Future 480-236-8367 ============================================================================================================================================================================================================ This message classified as Honeywell Internal by Hickman, Steve (AdvTech) on Tuesday, August 26, 2014 at 12:35:32 PM. The above classification labels are in accordance with the Honeywell Corporate Classification Policy. The information contained in this electronic message is confidential and intended only for the use of the individual/entity named above, and the information may be privileged. If you, the reader of this message, are not the intended recipient or an employee or agent responsible to deliver this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please immediately notify the sender and delete the original message. ============================================================================================================================================================================================================

On Tue, Aug 26, 2014 at 8:35 PM, Hickman, Steve (AdvTech) <Steve.Hickman@honeywell.com> wrote:
Smart pointers (as in http://www.boost.org/doc/libs/1_56_0/libs/smart_ptr/smart_ptr.htm ) assume that the action you want to perform when the count goes to zero is to free the memory pointed to. That isn’t the only use for reference counting. Why doesn’t the Smart Pointer library decouple the reference counting from the action to be taken and provide a generic reference counting mechanism that will call an arbitrary function when the count goes to zero? The default can be “delete” to provide the expected memory management capability but it would provide a robust mechanism for those who need other capabilities.
You can pass in a deleter (it's an argument to the constructors, not part of the type). Doesn't that do what you want?

On Tue, Aug 26, 2014 at 3:50 PM, Bruce Stephens <bruce.r.stephens@gmail.com> wrote:
On Tue, Aug 26, 2014 at 8:35 PM, Hickman, Steve (AdvTech) <Steve.Hickman@honeywell.com> wrote:
Why doesn’t the Smart Pointer library decouple the reference counting from the action to be taken and provide a generic reference counting mechanism that will call an arbitrary function when the count goes to zero? The
You can pass in a deleter (it's an argument to the constructors, not part of the type). Doesn't that do what you want?
Then there's intrusive_ptr<T>, which for a given T calls user-specified functions for both incrementing and decrementing the refcount... http://www.boost.org/doc/libs/1_56_0/libs/smart_ptr/intrusive_ptr.html

On Tue, Aug 26, 2014 at 8:58 PM, Nat Goodspeed <nat@lindenlab.com> wrote:
Then there's intrusive_ptr<T>, which for a given T calls user-specified functions for both incrementing and decrementing the refcount... http://www.boost.org/doc/libs/1_56_0/libs/smart_ptr/intrusive_ptr.html
That's true. With intrusive_ptr you have to supply your own counter, but presumably you're wanting to do that anyway in this case.
participants (3)
-
Bruce Stephens
-
Hickman, Steve (AdvTech)
-
Nat Goodspeed