TMCCountedPtr< T > Class Template Reference
[MCCore]
List of all members.
Detailed Description
template<class T>
class TMCCountedPtr< T >
Counted objects are objects that use a counter to keep track of how many other objects need them, and delete themselves when nobody needs them anymore. A counted object has an AddRef method that increments its counter, and a Release method that decrements it. When the value of the counter reaches zero, the object is deleted.
It is possible to call AddRef and Release "by hand" but it is a bad idea for at least two reasons. First, it is very easy to forget to add a call to Release, therefore causing a memory leak. Second the code becomes more complex because in every function that calls AddRef, you must consider exceptions. So you have to use a try/catch block, add a call to Release at the end of the try AND another one before re-throwing in the catch section...
Because they automatically call AddRef and Release, TMCCountedPtr, TMCCountedGetHelper and TMCCountedCreateHelper are your best friends.
TMCCountedPtr overrides many operators (including *, ->, &, =, and cast) so that you can use it like other pointers (the difference being the calls to AddRef and Release when you assign the pointer). Here is a pseudo code sample:
- Note:
- When using counted pointers as class members, you must be careful and avoid creating cycles (two or more objects pointing to each other). If you have cycles, the objects will never be deleted...
For more information, please refer to the "Counted Pointers" chapter in the overview of the SDK.
Constructor & Destructor Documentation
Member Function Documentation
|
template<class T> |
| T* TMCCountedPtr< T >::Assign |
( |
T ** |
pp, |
|
|
T * |
lp |
|
) |
[inline, static] |
|
|
template<class T> |
| void TMCCountedPtr< T >::CheckLastRef |
( |
void |
|
) |
[inline] |
|
|
template<class T> |
| T* const* TMCCountedPtr< T >::operator & |
( |
|
) |
const [inline] |
|
|
template<class T> |
| T** TMCCountedPtr< T >::operator & |
( |
|
) |
[inline] |
|
|
template<class T> |
| T& TMCCountedPtr< T >::operator * |
( |
|
) |
const [inline] |
|
|
template<class T> |
| TMCCountedPtr< T >::operator T * |
( |
|
) |
const [inline] |
|
|
template<class T> |
| BOOL TMCCountedPtr< T >::operator! |
( |
|
) |
[inline] |
|
|
template<class T> |
| T* TMCCountedPtr< T >::operator-> |
( |
|
) |
const [inline] |
|
|
template<class T> |
| T* TMCCountedPtr< T >::operator= |
( |
T * |
lp |
) |
[inline] |
|
Member Data Documentation
The documentation for this class was generated from the following file:
Generated on Mon Mar 14 12:29:08 2005 for Carrara SDK Doc by
1.3.9.1