#include <mcllib/MCRefPtr.h>
Inheritance diagram for MCRefPtr:
Public Member Functions | |
MCRefPtr (const MCRefPtr &r) | |
Copy constructor. | |
MCRefPtr (T *pHdl=0) | |
Attach to an MCRefCount derived object. | |
operator MCRefPtr () const | |
Conversion operator to help with const-ness. | |
operator T * () const | |
Get the contained object. | |
T * | operator-> () const |
Dereference the contained object. | |
bool | operator< (const MCRefPtr< T > &t) const |
Less-than operator for use in STL containers etc. | |
MCRefPtr & | operator= (const MCRefPtr &r) |
Assignment operator. | |
~MCRefPtr () | |
Detach from the object. | |
Protected Member Functions | |
void | attach (T *pHdl) |
void | detach () |
Protected Attributes | |
T * | m_pHdl |
Pointer to the MCRefCount derived implementation handle. |
In this implementation, the reference count is maintained within the data being pointed to rather than in a separate reference counted pointer. This means that the reference count and the data are intimately bound and cannot become disassociated (a problem with the alternative approach of using a separate ref count pointer). However the disadvantage is that the contained class must be derived from MCRefCount. This is not typically a problem.
Note that the class manipulates the reference count in a thread safe manner by default so it is safe to pass reference counted objects between threads using MCRefPtr. Where this is not required, greater performance can be obtained by using MCThreadModel::THRMODELSINGLE. This model uses reference counting that is not thread safe but is about 10-15 times faster than the thread safe reference counting. The single threaded model is about 5 times slower than not using reference counting at all (adopting some other strategy).
It is preferable to return const MCRefPtr<T>& from a method rather than MCRefPtr<T> to avoid the increment/decrement of the counter.
|
Attach to an MCRefCount derived object.
|
|
Detach from the object. The object's reference count is decremented. If it reaches zero the object is deleted. |
|
Copy constructor.
|
|
Get the contained object.
|
|
Dereference the contained object.
|
|
Less-than operator for use in STL containers etc. Invokes the less-than operator on the contained object addresses not on the the values that the object refers to.
|
|
Assignment operator.
|