©2004,2008 Jim E. Brooks http://www.palomino3d.org
[2006,2007/06]
[2008/02] shptr is a #define for osg::ref_ptr which is equivalent.
This is a vestige from Version 2 (SharedPtr code isn't compiled in Version 3).
C++ objects can be shared in different ways (objects in the general sense).
SharedPtr is a smart pointer that maintains a reference-count. A requirement is that objects to share must be derived from Shared. Shared provides storage for the reference-count, intrusively in an object itself, since Shared is its base class.
Besides sharing, SharedPtr simplifies object ownership. SharedPtr auto-deletes the object when it is no longer referenced, eliminating needing to explicitly delete an object.
NOTE: For speed, regular SharedPtr does not support NULL. The slower variant SharedPtrNull does.
A particular Shared object is interchangable with different kinds of SharedPtrs. SharedPtr::PTR() can extract the Shared object which can be used to create another SharedPtr variable of the same or different type.
An idiom is using a SharedPtr for its auto-deletion ability, even though the object really isn't shared.
Constructors with the potential to produce multitudes of objects with duplicate values can be constrained using UniquePtr. When given an object, the UniquePtr ctor may substitute the object with a shared one in a private STL set and delete the given duplicate object. UniquePtr shares copies that it owns rather than originals (which it doesn't own).
Last modified: Mon Apr 7 11:33:14 EDT 2008