Processes wide dynamic memory API.
Macros | |
#define | DWALLOC_API_PUBLIC |
Typedefs | |
typedef void(* | dwDynamicMemoryErrorCallback) (dwDynamicMemoryError error, size_t lastRequestedSizeInByte, void *userData) |
typedef void(* | dwDynamicMemoryFreeCallback) (void *addr, void *userData) |
typedef void *(* | dwDynamicMemoryMallocCallback) (size_t sizeInByte, void *userData) |
Enumerations | |
enum | dwDynamicMemoryError { DW_DYNAMIC_MEMORY_SUCCESS = 0, DW_DYNAMIC_MEMORY_BAD_ALLOC, DW_DYNAMIC_MEMORY_ALLOC_NOT_ALLOWED, DW_DYNAMIC_MEMORY_FREE_NOT_ALLOWED } |
Error to be reported through error callback. More... | |
enum | dwRuntimeMode { DW_MODE_INIT = 0x0000, DW_MODE_RUNTIME = 0x0001, DW_MODE_CLEANUP = 0x0002, DW_MODE_COUNT = 3 } |
Context runtime mode. More... | |
Functions | |
DWALLOC_API_PUBLIC void | dwDynamicMemory_free (void *ptr) |
Release memory chunk previously allocated with dwDynamicMemory_malloc() . More... | |
DWALLOC_API_PUBLIC void | dwDynamicMemory_getCallbacks (dwDynamicMemoryMallocCallback *mallocCallback, dwDynamicMemoryFreeCallback *freeCallback, void **userData) |
Get callbacks and user-defined general pointer previously passed in dwDynamicMemory_initialize. More... | |
DWALLOC_API_PUBLIC bool | dwDynamicMemory_getRuntimeMode (dwRuntimeMode *mode) |
Return currently selected runtime mode. More... | |
DWALLOC_API_PUBLIC void | dwDynamicMemory_initialize (dwDynamicMemoryMallocCallback mallocCallback, dwDynamicMemoryFreeCallback freeCallback, void *userData) |
Initialize dwDynamicMemory with user-defined callback for user space memory allocations. More... | |
DWALLOC_API_PUBLIC void * | dwDynamicMemory_malloc (size_t size) |
Allocate chunk of memory using allocator passed through dwDynamicMemory_initialize() . More... | |
DWALLOC_API_PUBLIC void | dwDynamicMemory_release () |
Release dwDynamicMemory. More... | |
DWALLOC_API_PUBLIC void | dwDynamicMemory_setErrorCallback (dwDynamicMemoryErrorCallback errorCallback, void *userData) |
Set error callback to be executed on an allocation error. More... | |
DWALLOC_API_PUBLIC bool | dwDynamicMemory_setRuntimeMode (dwRuntimeMode newMode) |
Switch runtime mode for all Driveworks SDK. More... | |
#define DWALLOC_API_PUBLIC |
Definition at line 56 of file DynamicMemory.h.
typedef void(* dwDynamicMemoryErrorCallback) (dwDynamicMemoryError error, size_t lastRequestedSizeInByte, void *userData) |
Definition at line 75 of file DynamicMemory.h.
typedef void(* dwDynamicMemoryFreeCallback) (void *addr, void *userData) |
Definition at line 74 of file DynamicMemory.h.
typedef void*(* dwDynamicMemoryMallocCallback) (size_t sizeInByte, void *userData) |
Definition at line 73 of file DynamicMemory.h.
enum dwDynamicMemoryError |
Error to be reported through error callback.
Definition at line 66 of file DynamicMemory.h.
enum dwRuntimeMode |
Context runtime mode.
Definition at line 119 of file DynamicMemory.h.
DWALLOC_API_PUBLIC void dwDynamicMemory_free | ( | void * | ptr | ) |
Release memory chunk previously allocated with dwDynamicMemory_malloc()
.
[in] | ptr | Pointer to the memory to release. |
DWALLOC_API_PUBLIC void dwDynamicMemory_getCallbacks | ( | dwDynamicMemoryMallocCallback * | mallocCallback, |
dwDynamicMemoryFreeCallback * | freeCallback, | ||
void ** | userData | ||
) |
Get callbacks and user-defined general pointer previously passed in dwDynamicMemory_initialize.
Optionally pass NULL if not interested in retrieving the pointers
[out] | mallocCallback | returned by pointer address of the mallocCallback. |
[out] | freeCallback | returned by pointer address of the freeCallback. |
[out] | userData | returned by pointer value of previously passed userData during initialization. |
DWALLOC_API_PUBLIC bool dwDynamicMemory_getRuntimeMode | ( | dwRuntimeMode * | mode | ) |
Return currently selected runtime mode.
[out] | mode | Pointer to mode where result to be returned |
DWALLOC_API_PUBLIC void dwDynamicMemory_initialize | ( | dwDynamicMemoryMallocCallback | mallocCallback, |
dwDynamicMemoryFreeCallback | freeCallback, | ||
void * | userData | ||
) |
Initialize dwDynamicMemory with user-defined callback for user space memory allocations.
If initialization is not performed or if user provides NULL pointers for the callbacks then posix_memalign() will be used for heap allocation and free() for deallocation.
The mallocCallback must always return 16-byte aligned memory.
[in] | mallocCallback | functions which will be used for memory allocation. NULL for CRT implementation |
[in] | freeCallback | functions which will be used for memory deallocation. NULL for CRT implementation |
[in] | userData | general pointer to something understandable by mallocCallback or freeCallback |
DWALLOC_API_PUBLIC void* dwDynamicMemory_malloc | ( | size_t | size | ) |
Allocate chunk of memory using allocator passed through dwDynamicMemory_initialize()
.
If not enough memory is available for allocation, nullptr is returned;
[in] | size | Size in bytes of memory chunk to allocate. |
DWALLOC_API_PUBLIC void dwDynamicMemory_release | ( | ) |
Release dwDynamicMemory.
After this call all following requests for memory allocation will use the CRT heap allocation mechanisms.
DWALLOC_API_PUBLIC void dwDynamicMemory_setErrorCallback | ( | dwDynamicMemoryErrorCallback | errorCallback, |
void * | userData | ||
) |
Set error callback to be executed on an allocation error.
[in] | errorCallback | Callback to be called on any error. |
[in] | userData | User pointer to return back through the error callback |
DWALLOC_API_PUBLIC bool dwDynamicMemory_setRuntimeMode | ( | dwRuntimeMode | newMode | ) |
Switch runtime mode for all Driveworks SDK.
A runtime mode is activated after full initialization phase. Switching to runtime mode allows context to perform checks if for example heap allocations are still hapenning. Runtime mode does not have any effect on the performance of the SDK modules, it can, however, used for debugging purpose.
[in] | newMode | mode that you want to setup |