#include <StatMemAlloc.h>
Inheritance diagram for StatObjAlloc
Public Methods | |
StatObjAlloc (ppSizeT capacity = 0) | |
Refer to the constructor of StatMemAlloc. | |
~StatObjAlloc () | |
Refer to the destructor of StatMemAlloc. | |
void* | Allocate () |
This method is a convinience method only. More... | |
OBJ* | ConstructAllocate () |
This method allocates memory for an object of type OBJ via the method Allocate(). More... | |
void | DestructReset (ppSizeT capacity = 0) |
DestructReset() destructs all memory that has been allocated by this object. More... |
StatObjAlloc behaves very much like its parent class, StatMemAlloc. Actually, it behaves exactly like StatMemAlloc, except for the fact that it implements two additional methods, ConstructAllocate() and DestructReset().
As the names migth suggest, ConstructAllocate() not only allocates memory for an object of type OBJ, but also constructs this memory using the default constructor. DestructReset() destructs all memory that has been allocated. you want to be carefull when using Allocate() together with DestructReset(), as all memory that StatObjAlloc has allocated migth not be constructed, and invoking a destructor on non-constructed memory is very bad.
The basic concept is exactly the same for both StatObjAlloc and StatMemAlloc. Refer to StatMemAlloc to get a more detailed description of how both of these classes work.
|
This method is a convinience method only. It calls Allocate(sizeof(OBJ)) and returns the return value. The convinience lies in that you don't have to pass the sizeof(OBJ) as a parameter. The parameterless overload of Allocate() does not hide the single parameter overload enherited from StatMemAlloc. |
|
This method allocates memory for an object of type OBJ via the method Allocate(). This migth result in an exception of type bad_alloc that ConstructAllocate() does not catch. ConstructAllocate() also constructs the allocated memory using the default constructor of class OBJ. If this constructor results in an exception, ConstructAllocate() catches it, deallocates the allocated memory, and rethrows the exception. Finally, ConstructAllocate() returns the address of the newly allocated and constructed object. |
|
DestructReset() destructs all memory that has been allocated by this object. This includes memory that has been obtained via the method Allocate(), which migth not have been constructed. If this is not desired behavior, use Reset() instead of DestructReset(). After the used memory has been destructed, DestructReset() calls Reset(capacity), where the capacity parameter of Reset() is the capacity parameter of DestructReset(). After this point, DeconstructReset() behaves exactly like Reset(). If an invocation of the destructor of class OBJ results in an exception, DestructReset() does not catch it. This means that the memory that has not yet been deconstructed at the time the exception is thrown, doesn't get destructed at all, as the process is interrupted by the resulting exception. Reset() also doesn't get called. Throwing exceptions from destructors is bad programming practice, so even though some allocators, unlike StatObjAlloc, can handle it, do your best to avoid it. |