class RED::MemoryAllocator
Memory allocation class. More...
#include <REDMemoryAllocator.h>
Public functions:
void * | Allocate ( size_t iSize, int iCaller ) |
void * | Allocate ( size_t iSize ) |
void | Free ( void * iAddress ) |
RED::MemoryLeakTracker * | GetMemoryLeakTracker ( ) const |
void * | Reallocate ( void * iSource, size_t iSize, int iCaller ) |
void * | Reallocate ( void * iSource, size_t iSize ) |
RED_CUSTOM_DELETE | SetCustomDelete ( RED_CUSTOM_DELETE iCustomDelete ) |
RED_CUSTOM_DELETE | SetCustomDeleteArray ( RED_CUSTOM_DELETE iCustomDeleteArray ) |
RED_CUSTOM_NEW | SetCustomNew ( RED_CUSTOM_NEW iCustomNew ) |
RED_CUSTOM_NEW | SetCustomNewArray ( RED_CUSTOM_NEW iCustomNewArray ) |
RED_CUSTOM_REALLOC | SetCustomRealloc ( RED_CUSTOM_REALLOC iCustomRealloc ) |
void | SetMemoryTracking ( bool iTracking ) |
Public static functions:
static MemoryAllocator & | Get ( ) |
Public typedefs:
typedef void(* | RED_CUSTOM_DELETE )(void *iMemory) |
typedef void *(* | RED_CUSTOM_NEW )(size_t iSize) |
typedef void *(* | RED_CUSTOM_REALLOC )(void *iMemory, size_t iSize) |
Protected functions:
MemoryAllocator ( ) | |
~MemoryAllocator ( ) |
Protected variables:
RED_CUSTOM_DELETE | _delete |
RED_CUSTOM_DELETE | _deletearray |
RED::MemoryLeakTracker * | _mlt |
RED_CUSTOM_NEW | _new |
RED_CUSTOM_NEW | _newarray |
RED_CUSTOM_REALLOC | _realloc |
Detailed description:
Memory allocation class.
This class is a singleton class (it can be instantiated once). It encapsulates memory management routines. Every instance of the RED engine will use this allocator to perform memory allocation and management. A SDK user can freely plug its memory allocation/deallocation callbacks through this class to gain control over the memory management.
The memory allocator is accessed using RED::MemoryAllocator::Get.
A memory leak tracking tool (RED::MemoryLeakTracker) can be accessed from the memory allocator's instance (see the RED::MemoryAllocator::GetMemoryLeakTracker method).
Functions documentation
protected RED::MemoryAllocator::MemoryAllocator | ( | ) |
Default constructor.
protected RED::MemoryAllocator::~MemoryAllocator | ( | ) |
Default destructor.
public static MemoryAllocator & RED::MemoryAllocator::Get | ( | ) |
Returns the unique instance of the MemoryAllocator class.
Returns:
public void * RED::MemoryAllocator::Allocate | ( | size_t | iSize, |
int | iCaller | ||
) |
Memory allocation method.
Parameters:
iSize: | Byte size of the allocation. |
iCaller: | Identifier of the allocation caller. |
Returns:
public void * RED::MemoryAllocator::Allocate | ( | size_t | iSize | ) |
Memory allocation method.
This allocation method does not provide any caller information.
Parameters:
iSize: | Byte size of the allocation. |
Returns:
public void RED::MemoryAllocator::Free | ( | void * | iAddress | ) |
Releases a memory chunk.
Parameters:
iAddress: | Released memory address. |
public RED::MemoryLeakTracker * RED::MemoryAllocator::GetMemoryLeakTracker | ( | ) const |
Gets the memory leak tracker.
Returns:
public void * RED::MemoryAllocator::Reallocate | ( | void * | iSource, |
size_t | iSize, | ||
int | iCaller | ||
) |
Memory re-allocation method.
Note that this method do not go through overloaded new / delete operators. This method will release the 'iSource' memory upon a failure to reallocate iSource with 'iSize' bytes. In this case, the method returns NULL. Note that the standard C++ realloc behavior does not release the source memory segment on failure to extend it, unlike what this method does.
Parameters:
iSource: | Address whose memory size is to be modified. |
iSize: | Byte size of the allocation. |
iCaller: | Identifier of the allocation caller. |
Returns:
public void * RED::MemoryAllocator::Reallocate | ( | void * | iSource, |
size_t | iSize | ||
) |
Memory re-allocation method.
Note that this method do not go through overloaded new / delete operators. This method will release the 'iSource' memory upon a failure to reallocate iSource with 'iSize' bytes. In this case, the method returns NULL. Note that the standard C++ realloc behavior does not release the source memory segment on failure to extend it, unlike what this method does.
Parameters:
iSource: | Address whose memory size is to be modified. |
iSize: | Byte size of the allocation. |
Returns:
public RED_CUSTOM_DELETE RED::MemoryAllocator::SetCustomDelete | ( | RED_CUSTOM_DELETE | iCustomDelete | ) |
Sets a custom delete operator.
The custom delete operator will be used for all the RED::Object or inherited destructions. Call this method passing NULL to reset to the default system delete operator.
Parameters:
iCustomDelete: | A pointer to the custom delete operator. |
Returns:
public RED_CUSTOM_DELETE RED::MemoryAllocator::SetCustomDeleteArray | ( | RED_CUSTOM_DELETE | iCustomDeleteArray | ) |
Sets a custom delete array operator.
The custom delete array operator will be used for all the RED::Object or inherited destructions. Call this method passing NULL to reset to the default system delete array operator.
Parameters:
iCustomDeleteArray: | A pointer to the custom delete array operator. |
Returns:
public RED_CUSTOM_NEW RED::MemoryAllocator::SetCustomNew | ( | RED_CUSTOM_NEW | iCustomNew | ) |
Sets a custom new operator.
The custom new operator will be used for all the RED::Object or inherited creations. Call this method passing NULL to reset to the default system new operator.
Parameters:
iCustomNew: | A pointer to the custom new operator. |
Returns:
public RED_CUSTOM_NEW RED::MemoryAllocator::SetCustomNewArray | ( | RED_CUSTOM_NEW | iCustomNewArray | ) |
Sets a custom new array operator.
The custom new array operator will be used for all the RED::Object or inherited creations. Call this method passing NULL to reset to the default system new array operator.
Parameters:
iCustomNewArray: | A pointer to the custom new array operator. |
Returns:
public RED_CUSTOM_REALLOC RED::MemoryAllocator::SetCustomRealloc | ( | RED_CUSTOM_REALLOC | iCustomRealloc | ) |
Sets a custom realloc operator.
The custom realloc operator will be called in replacement of each call to rrealloc or by RED::MemoryAllocator::Reallocate(). Call this method passing NULL to reset to the default system realloc operator.
Parameters:
iCustomRealloc: | A pointer to the custom realloc operator. |
Returns:
public void RED::MemoryAllocator::SetMemoryTracking | ( | bool | iTracking | ) |
Enables or disables memory tracking.
Please note that the memory is only tracked after the memory tracking has started and stops being tracked after the memory tracking has been disabled.
If enabled at the application's termination, the memory leak tracker will automatically dump all remaining allocations that are leaks.
Parameters:
iTracking: | On / Off. |
Variables documentation
Pointer to the memory deallocation method.
Pointer to the memory array deallocation method.
Pointer to the instance of the memory leak tracker.
Pointer to the memory allocation method.
Pointer to the memory array allocation method.
Pointer to the memory reallocation method.
Types documentation
Custom memory de-allocator.
Custom memory allocator.
Custom memory re-allocator.