GaSmartStorage
template class provides reference-counting for smart pointers. GaSmartStorage
objects holds address of used data and number of references (smart pointers) which point to the data. Object of this class as well as the data are destroyed and memory is freed when there are no more references which points to the data. Arrays cannot be used with this class. This class has no built-in synchronizator, so LOCK_OBJECT
and LOCK_THIS_OBJECT
macros cannot be used with instances of this class, but all public method and operators are thread-safe.
More...
#include <D:/Temp/vs/gal/source/SmartPtr.h>
Public Member Functions | |
GaSmartStorage (T *data) | |
Initializes object for counting references to data located at data address. | |
~GaSmartStorage () | |
Destructor is called when there are no more references which points to the data. Destructor frees memory used by the data. | |
T *GACALL | GetData () const |
This method is thread-safe. | |
int GACALL | GetCount () const |
This method is thread-safe. | |
Static Public Member Functions | |
static GaSmartPtr< T > GACALL | MakeInstance (T *data) |
MakeInstance makes new reference-counting object for data at address data. This method is thread-safe. | |
static GaSmartStorage< T > *GACALL | MakeInstanceDirect (T *data) |
MakeInstance makes new reference-counting object for data at address data. This method is thread-safe. | |
static int GACALL | AddReference (GaSmartStorage< T > *location) |
This method increments number of references to the data. AddReference method is called when smart pointer is set to point to the location. This method is thread-safe. | |
static int GACALL | RemoveReference (GaSmartStorage< T > *location) |
This method decrements number of references, if that number reaches 0, the data is destroyed and memory is freed. RemoveReference method is called when smart pointers are destructed or when set to point to new location. This method is thread-safe. | |
Private Attributes | |
int | _count |
Holds number of references (smart pointers) to data guarded by this object. | |
T * | _data |
Pointer to user data. | |
Friends | |
class | GaSmartPtr< T > |
GaSmartStorage
template class provides reference-counting for smart pointers. GaSmartStorage
objects holds address of used data and number of references (smart pointers) which point to the data. Object of this class as well as the data are destroyed and memory is freed when there are no more references which points to the data. Arrays cannot be used with this class. This class has no built-in synchronizator, so LOCK_OBJECT
and LOCK_THIS_OBJECT
macros cannot be used with instances of this class, but all public method and operators are thread-safe.
Common::GaSmartStorage< T >::GaSmartStorage | ( | T * | data | ) | [inline] |
Initializes object for counting references to data located at data
address.
data | pointer to user data. data cannot be an array. |
Common::GaSmartStorage< T >::~GaSmartStorage | ( | ) | [inline] |
Destructor is called when there are no more references which points to the data. Destructor frees memory used by the data.
static GaSmartPtr<T> GACALL Common::GaSmartStorage< T >::MakeInstance | ( | T * | data | ) | [inline, static] |
MakeInstance
makes new reference-counting object for data at address data. This method is thread-safe.
data | pointer to data. data cannot be an array. |
static GaSmartStorage<T>* GACALL Common::GaSmartStorage< T >::MakeInstanceDirect | ( | T * | data | ) | [inline, static] |
MakeInstance
makes new reference-counting object for data at address data. This method is thread-safe.
data | pointer to data. data cannot be an array. |
static int GACALL Common::GaSmartStorage< T >::AddReference | ( | GaSmartStorage< T > * | location | ) | [inline, static] |
This method increments number of references to the data. AddReference
method is called when smart pointer is set to point to the location. This method is thread-safe.
location | pointer to location which is incremented. |
static int GACALL Common::GaSmartStorage< T >::RemoveReference | ( | GaSmartStorage< T > * | location | ) | [inline, static] |
This method decrements number of references, if that number reaches 0, the data is destroyed and memory is freed. RemoveReference
method is called when smart pointers are destructed or when set to point to new location. This method is thread-safe.
location | pointer to location which is decremented. |
T* GACALL Common::GaSmartStorage< T >::GetData | ( | ) | const [inline] |
This method is thread-safe.
int GACALL Common::GaSmartStorage< T >::GetCount | ( | ) | const [inline] |
This method is thread-safe.
friend class GaSmartPtr< T > [friend] |
int Common::GaSmartStorage< T >::_count [mutable, private] |
Holds number of references (smart pointers) to data guarded by this object.
T* Common::GaSmartStorage< T >::_data [private] |
Pointer to user data.