Newton Dynamics  4.00
dMemory Class Reference

Static Public Member Functions

static D_CORE_API void * Malloc (size_t size)
 General Memory allocation function. More...
 
static D_CORE_API void Free (void *const ptr)
 Destroy a memory buffer previously allocated by Malloc.
 
static D_CORE_API dUnsigned64 GetMemoryUsed ()
 Return the total memory allocated by the newton engine and tools.
 
static D_CORE_API void SetMemoryAllocators (dMemAllocCallback alloc, dMemFreeCallback free)
 Install low level system memory allocation functions. More...
 

Member Function Documentation

◆ Malloc()

void * dMemory::Malloc ( size_t  size)
static

General Memory allocation function.

All memory allocations used by the Newton Engine and Tools are performed by calling this function.

◆ SetMemoryAllocators()

void dMemory::SetMemoryAllocators ( dMemAllocCallback  alloc,
dMemFreeCallback  free 
)
static

Install low level system memory allocation functions.

Parameters
dMemAllocCallbackalloc: is a function pointer callback to allocate a memory chunk.
dMemFreeCallbackfree: is a function pointer callback to free a memory chunk.

All memory allocated by alloc, does not need to be aligned, therefore an application can write them using standard malloc and free. By default the memory allocation is set to call the standard library functions malloc and free, however if an application wants to keep track of how memory is used, it must install the memory callbacks by calling this function before any class of the Newton Engine or tool was created or instantiated. The engine does not do any global allocation using global operators new and delete, therefore it is ok to install the memory allocator on the main of the application or just before start using the engine.