#include <MemAlloc.h>
Inheritance diagram for ObjAlloc
Public Methods | |
ObjAlloc (ppu32 blockSize = 16) | |
blockSize is the amount of objects of type OBJ ObjAlloc allocates memory for in each block. | |
~ObjAlloc () | |
Refer to the destructor of MemAlloc. | |
OBJ* | ConstructAllocate () |
This method allocates memory for an object of type OBJ via the MemAlloc method Allocate(). More... | |
void | DestructDeallocate (OBJ* pObj) |
ConstructAllocate() destructs the object of type OBJ pointed to by the pObj argument. More... |
ObjAlloc behaves very much like its parent class, MemAlloc. Actually, it behaves exactly like MemAlloc, except for the fact that it implements two additional methods, ConstructAllocate() and DestructDeallocate().
As the names migth suggest, these two classes not only (de)allocates memory for an object of type OBJ, but also de-/constructs this memory using the destructor or the default constructor.
The unit size of ObjAlloc is equal to sizeof(OBJ), and cannot be set at runtime.
The basic concept is exactly the same for both ObjAlloc and MemAlloc. Refer to MemAlloc to get a more detailed description of how both of these classes work.
|
This method allocates memory for an object of type OBJ via the MemAlloc method Allocate(). This call to Allocate() migth result in an exception of type bad_alloc that ConstructAllocate() does not catch. ConstructAllocate() also constructs the allocated memory using the default constructor. If this constructor throws 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. |
|
ConstructAllocate() destructs the object of type OBJ pointed to by the pObj argument. After that, the memory pointed to by the pObj argument is deallocated via the MemAlloc method Deallocate(). If an exception is thrown from the called constructor, the memory pointed to by pObj is still deallocated. The exception is then rethrown. Throwing exceptions from destructors is bad programming practice, so even though ObjAlloc can handle it, do your best to avoid it. |