Processes wide dynamic memory API.
Macros | |
| #define | DWALLOC_PRAGMA_COVERITY(s) |
| #define | DWALLOC_API_PUBLIC |
Typedefs | |
| typedef void *(* | dwDynamicMemoryMallocCallback) (size_t sizeInByte, void *userData) |
| typedef void(* | dwDynamicMemoryFreeCallback) (void *addr, void *userData) |
| typedef void(* | dwDynamicMemoryErrorCallback) (dwDynamicMemoryError error, size_t lastRequestedSizeInByte, 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_initialize (dwDynamicMemoryMallocCallback mallocCallback, dwDynamicMemoryFreeCallback freeCallback, void *const userData) |
| Initialize dwDynamicMemory with user-defined callback for user space memory allocations. More... | |
| DWALLOC_API_PUBLIC void | dwDynamicMemory_setErrorCallback (dwDynamicMemoryErrorCallback errorCallback, void *const userData) |
| Set error callback to be executed on an allocation/free during runtime mode. More... | |
| DWALLOC_API_PUBLIC void | dwDynamicMemory_getCallbacks (dwDynamicMemoryMallocCallback *const mallocCallback, dwDynamicMemoryFreeCallback *const freeCallback, void **const userData) |
| Get callbacks and user-defined general pointer previously passed in dwDynamicMemory_initialize. More... | |
| DWALLOC_API_PUBLIC bool | dwDynamicMemory_setRuntimeMode (dwRuntimeMode const newMode) |
| Switch runtime mode for all Driveworks SDK. More... | |
| DWALLOC_API_PUBLIC bool | dwDynamicMemory_getRuntimeMode (dwRuntimeMode *const mode) |
| Return currently selected runtime mode. More... | |
| DWALLOC_API_PUBLIC void | dwDynamicMemory_release (void) |
| Release dwDynamicMemory. More... | |
| DWALLOC_API_PUBLIC void * | dwDynamicMemory_malloc (size_t const size) |
Allocate chunk of memory using allocator passed through dwDynamicMemory_initialize(). More... | |
| DWALLOC_API_PUBLIC void | dwDynamicMemory_free (void *const ptr) |
Release memory chunk previously allocated with dwDynamicMemory_malloc(). More... | |
| #define DWALLOC_API_PUBLIC |
Definition at line 60 of file DynamicMemory.h.
| #define DWALLOC_PRAGMA_COVERITY | ( | s | ) |
Definition at line 45 of file DynamicMemory.h.
| typedef void(* dwDynamicMemoryErrorCallback) (dwDynamicMemoryError error, size_t lastRequestedSizeInByte, void *userData) |
Definition at line 81 of file DynamicMemory.h.
Definition at line 80 of file DynamicMemory.h.
Definition at line 79 of file DynamicMemory.h.
| enum dwDynamicMemoryError |
Error to be reported through error callback.
Definition at line 72 of file DynamicMemory.h.
| enum dwRuntimeMode |
Context runtime mode.
Definition at line 158 of file DynamicMemory.h.
| DWALLOC_API_PUBLIC void dwDynamicMemory_free | ( | void *const | ptr | ) |
Release memory chunk previously allocated with dwDynamicMemory_malloc().
| [in] | ptr | Pointer to the memory to release. |
ptr is either NULL or was returned by a prior call to dwDynamicMemory_malloc() under the currently active allocation path (i.e. the matching free path must still be installed: memory obtained via the user-defined mallocCallback must be freed before dwDynamicMemory_release() switches the path back to the CRT, and vice versa). ptr is non-NULL, the block is released through the active deallocator (the user-defined freeCallback if installed, otherwise the CRT free()). | DWALLOC_API_PUBLIC void dwDynamicMemory_getCallbacks | ( | dwDynamicMemoryMallocCallback *const | mallocCallback, |
| dwDynamicMemoryFreeCallback *const | freeCallback, | ||
| void **const | 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 *const | mode | ) |
Return currently selected runtime mode.
| [out] | mode | Pointer to mode where result to be returned |
mode points to a writable dwRuntimeMode location. mode is NULL, returns false and no value is written. | DWALLOC_API_PUBLIC void dwDynamicMemory_initialize | ( | dwDynamicMemoryMallocCallback | mallocCallback, |
| dwDynamicMemoryFreeCallback | freeCallback, | ||
| void *const | 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.
| [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 |
mallocCallback and freeCallback are either both NULL (revert to CRT path) or both non-NULL and form a matched alloc/free pair; the alloc must return 16-byte aligned memory. mallocCallback / freeCallback when both are non-NULL; otherwise they fall back to posix_memalign()/free(). userData is forwarded as the userData argument to every subsequent invocation of mallocCallback / freeCallback. | DWALLOC_API_PUBLIC void* dwDynamicMemory_malloc | ( | size_t const | 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. |
size bytes or NULL. | DWALLOC_API_PUBLIC void dwDynamicMemory_release | ( | void | ) |
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 *const | userData | ||
| ) |
Set error callback to be executed on an allocation/free during runtime mode.
| [in] | errorCallback | Callback to be called on any error. May be NULL to disable reporting. |
| [in] | userData | User pointer to return back through the error callback |
errorCallback with userData as the third argument:errorCallback is NULL, error events are silently dropped. | DWALLOC_API_PUBLIC bool dwDynamicMemory_setRuntimeMode | ( | dwRuntimeMode const | 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 |
newMode and is observable via dwDynamicMemory_getRuntimeMode(). The behavior of subsequent malloc/free is governed by the new mode (see dwRuntimeMode). newMode is not one of DW_MODE_INIT / DW_MODE_RUNTIME / DW_MODE_CLEANUP), the active runtime mode is silently reset to DW_MODE_INIT.