DriveWorks SDK Reference
3.0.4260 Release
For Test and Development only

Core Dynamic Memory

Detailed Description

Processes wide dynamic memory API.

Note
SW Release Applicability: These APIs are available in both NVIDIA DriveWorks and NVIDIA DRIVE Software releases.

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...
 

Macro Definition Documentation

◆ DWALLOC_API_PUBLIC

#define DWALLOC_API_PUBLIC

Definition at line 56 of file DynamicMemory.h.

Typedef Documentation

◆ dwDynamicMemoryErrorCallback

typedef void(* dwDynamicMemoryErrorCallback) (dwDynamicMemoryError error, size_t lastRequestedSizeInByte, void *userData)

Definition at line 75 of file DynamicMemory.h.

◆ dwDynamicMemoryFreeCallback

typedef void(* dwDynamicMemoryFreeCallback) (void *addr, void *userData)

Definition at line 74 of file DynamicMemory.h.

◆ dwDynamicMemoryMallocCallback

typedef void*(* dwDynamicMemoryMallocCallback) (size_t sizeInByte, void *userData)

Definition at line 73 of file DynamicMemory.h.

Enumeration Type Documentation

◆ dwDynamicMemoryError

Error to be reported through error callback.

Enumerator
DW_DYNAMIC_MEMORY_SUCCESS 

no error

DW_DYNAMIC_MEMORY_BAD_ALLOC 

Memory allocation failed, probably not enough memory.

DW_DYNAMIC_MEMORY_ALLOC_NOT_ALLOWED 

Allocation is currently not allowed, because in runtime mode.

DW_DYNAMIC_MEMORY_FREE_NOT_ALLOWED 

Memory release is currently not allowed, because in runtime mode.

Definition at line 66 of file DynamicMemory.h.

◆ dwRuntimeMode

Context runtime mode.

Enumerator
DW_MODE_INIT 

Heap memory allocations and deallocations are allowed. Default.

DW_MODE_RUNTIME 

Heap memory allocations are not allowed.

DW_MODE_CLEANUP 

Heap memory allocations and deallocations are allowed.

DW_MODE_COUNT 

Definition at line 119 of file DynamicMemory.h.

Function Documentation

◆ dwDynamicMemory_free()

DWALLOC_API_PUBLIC void dwDynamicMemory_free ( void *  ptr)

Release memory chunk previously allocated with dwDynamicMemory_malloc().

Parameters
[in]ptrPointer to the memory to release.

◆ dwDynamicMemory_getCallbacks()

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

Parameters
[out]mallocCallbackreturned by pointer address of the mallocCallback.
[out]freeCallbackreturned by pointer address of the freeCallback.
[out]userDatareturned by pointer value of previously passed userData during initialization.

◆ dwDynamicMemory_getRuntimeMode()

DWALLOC_API_PUBLIC bool dwDynamicMemory_getRuntimeMode ( dwRuntimeMode mode)

Return currently selected runtime mode.

Parameters
[out]modePointer to mode where result to be returned
Returns
false if given pointer is null otherwise true

◆ dwDynamicMemory_initialize()

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.

Parameters
[in]mallocCallbackfunctions which will be used for memory allocation. NULL for CRT implementation
[in]freeCallbackfunctions which will be used for memory deallocation. NULL for CRT implementation
[in]userDatageneral pointer to something understandable by mallocCallback or freeCallback

◆ dwDynamicMemory_malloc()

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;

Parameters
[in]sizeSize in bytes of memory chunk to allocate.
Returns
Pointer to the begnning of the memory block or nullptr if there is not enough space to allocate the requested chunk.

◆ dwDynamicMemory_release()

DWALLOC_API_PUBLIC void dwDynamicMemory_release ( )

Release dwDynamicMemory.

After this call all following requests for memory allocation will use the CRT heap allocation mechanisms.

◆ dwDynamicMemory_setErrorCallback()

DWALLOC_API_PUBLIC void dwDynamicMemory_setErrorCallback ( dwDynamicMemoryErrorCallback  errorCallback,
void *  userData 
)

Set error callback to be executed on an allocation error.

Parameters
[in]errorCallbackCallback to be called on any error.
[in]userDataUser pointer to return back through the error callback

◆ dwDynamicMemory_setRuntimeMode()

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.

Parameters
[in]newModemode that you want to setup
Returns
false if given enum is ininvalid otherwise true