Skip to main content
gamedev.net
🔒 Locked

[Sweet Snippets] A Shared Pointer implementation with explicit destruction

Started by Little Coding Fox Mar 22, 2011 at 11:07 AM 0 replies 1k views
Original Post
Little Coding Fox
Little Coding Fox
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]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.