[Sweet Snippets] A Shared Pointer implementation with explicit destruction

Started by
-1 comments, last by Little Coding Fox 13 years ago
Shared Pointers are used a lot in the game industry as a great method for safely sharing a pointer in multiple clients. However, often you'll have a Manager kind of class, that generates new objects and spews them out as Shared Pointers, and you often have to destroy those objects when the Manager is about to be destroyed, usually when terminating the app.

However, there's no way to explicitly destroy the objects, as they are only destroyed when the reference count becomes 0. However, using a simple Observer software pattern, you can destroy the object easily while keeping the safety that there is a way to verify whether the object is still valid. Attached to this thread is a sample implementation of a shared pointer that can explicitly destroy or replace the object contained within. Mind you however, that it is not a complete implementation and only serves as a sample.

[attachment=1691:SuperSmartPointer.zip]

This topic is closed to new replies.

Advertisement