class RED::MemoryAllocator

Memory allocation class. More...

#include <REDMemoryAllocator.h>

Public functions:

void *Allocate ( size_t iSize, int iCaller )
void *Allocate ( size_t iSize )
voidFree ( void * iAddress )
RED::MemoryLeakTracker *GetMemoryLeakTracker ( ) const
void *Reallocate ( void * iSource, size_t iSize, int iCaller )
void *Reallocate ( void * iSource, size_t iSize )
RED_CUSTOM_DELETESetCustomDelete ( RED_CUSTOM_DELETE iCustomDelete )
RED_CUSTOM_DELETESetCustomDeleteArray ( RED_CUSTOM_DELETE iCustomDeleteArray )
RED_CUSTOM_NEWSetCustomNew ( RED_CUSTOM_NEW iCustomNew )
RED_CUSTOM_NEWSetCustomNewArray ( RED_CUSTOM_NEW iCustomNewArray )
RED_CUSTOM_REALLOCSetCustomRealloc ( RED_CUSTOM_REALLOC iCustomRealloc )
voidSetMemoryTracking ( 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

Default constructor.

Default destructor.

Returns the unique instance of the MemoryAllocator class.

Returns:

A const reference to the unique instance of the MemoryAllocator.
public void * RED::MemoryAllocator::Allocate(size_tiSize,
intiCaller
)

Memory allocation method.

Parameters:

iSize:Byte size of the allocation.
iCaller:Identifier of the allocation caller.

Returns:

The allocated address. NULL in case of error.
public void * RED::MemoryAllocator::Allocate(size_tiSize)

Memory allocation method.

This allocation method does not provide any caller information.

Parameters:

iSize:Byte size of the allocation.

Returns:

The allocated address. NULL in case of error.
public void RED::MemoryAllocator::Free(void *iAddress)

Releases a memory chunk.

Parameters:

iAddress:Released memory address.

Gets the memory leak tracker.

Returns:

The address of the RED::MemoryLeakTracker instance used to keep track of all engine allocations. The returned address is NULL if the memory leak tracker has not been enabled.
public void * RED::MemoryAllocator::Reallocate(void *iSource,
size_tiSize,
intiCaller
)

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:

The allocated address. NULL in case of error.
public void * RED::MemoryAllocator::Reallocate(void *iSource,
size_tiSize
)

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:

The allocated address. NULL in case of error.

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:

A pointer to the old delete operator.

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:

A pointer to the old delete array operator.

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:

A pointer to the old new operator.

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:

A pointer to the old new array operator.

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:

A pointer to the old realloc operator.
public void RED::MemoryAllocator::SetMemoryTracking(booliTracking)

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

public typedef void(* RED::MemoryAllocator::RED_CUSTOM_DELETE)(void *iMemory)

Custom memory de-allocator.

public typedef void *(* RED::MemoryAllocator::RED_CUSTOM_NEW)(size_t iSize)

Custom memory allocator.

public typedef void *(* RED::MemoryAllocator::RED_CUSTOM_REALLOC)(void *iMemory, size_t iSize)

Custom memory re-allocator.