NVIDIA DriveOS Linux SDK API Reference

7.2.5.0 Early Access Release
Core Dynamic Memory

Detailed Description

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

Macro Definition Documentation

◆ DWALLOC_API_PUBLIC

#define DWALLOC_API_PUBLIC

Definition at line 60 of file DynamicMemory.h.

◆ DWALLOC_PRAGMA_COVERITY

#define DWALLOC_PRAGMA_COVERITY (   s)

Definition at line 45 of file DynamicMemory.h.

Typedef Documentation

◆ dwDynamicMemoryErrorCallback

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

Definition at line 81 of file DynamicMemory.h.

◆ dwDynamicMemoryFreeCallback

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

Definition at line 80 of file DynamicMemory.h.

◆ dwDynamicMemoryMallocCallback

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

Definition at line 79 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 72 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 trigger an error callback.

DW_MODE_CLEANUP 

Heap memory allocations and deallocations are allowed.

DW_MODE_COUNT 

Definition at line 158 of file DynamicMemory.h.

Function Documentation

◆ dwDynamicMemory_free()

DWALLOC_API_PUBLIC void dwDynamicMemory_free ( void *const  ptr)

Release memory chunk previously allocated with dwDynamicMemory_malloc().

Parameters
[in]ptrPointer to the memory to release.
Precondition
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).
Postcondition
If ptr is non-NULL, the block is released through the active deallocator (the user-defined freeCallback if installed, otherwise the CRT free()).
If the active runtime mode is DW_MODE_RUNTIME and an error callback is installed, the error callback is invoked with DW_DYNAMIC_MEMORY_FREE_NOT_ALLOWED before deallocation proceeds (the free is reported, not blocked).
API Group
  • Init: Yes
  • Runtime: No
  • De-Init: Yes

◆ dwDynamicMemory_getCallbacks()

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

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.
Precondition
Each non-NULL out-pointer points to a writable location of the matching type.
Postcondition
For every non-NULL out-pointer, the currently installed value is written: *mallocCallback / *freeCallback / *userData are set to the values last installed by dwDynamicMemory_initialize() (or NULL after dwDynamicMemory_release()).
Out-pointers passed as NULL are skipped; no internal state is modified.
API Group
  • Init: Yes
  • Runtime: Yes
  • De-Init: Yes

◆ dwDynamicMemory_getRuntimeMode()

DWALLOC_API_PUBLIC bool dwDynamicMemory_getRuntimeMode ( dwRuntimeMode *const  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
Precondition
If non-NULL, mode points to a writable dwRuntimeMode location.
Postcondition
If mode is NULL, returns false and no value is written.
Otherwise *mode is set to the currently active runtime mode (DW_MODE_INIT / DW_MODE_RUNTIME / DW_MODE_CLEANUP) and the function returns true.
Internal state of dwDynamicMemory is unchanged.
API Group
  • Init: Yes
  • Runtime: Yes
  • De-Init: Yes

◆ dwDynamicMemory_initialize()

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.

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
Precondition
Called only during the Init phase, before any concurrent allocation activity.
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.
Postcondition
Subsequent calls to dwDynamicMemory_malloc()/dwDynamicMemory_free() (and the overridden global new/delete operators) route through 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.
API Group
  • Init: Yes
  • Runtime: No
  • De-Init: No

◆ dwDynamicMemory_malloc()

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;

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.
Precondition
Calling dwDynamicMemory_initialize() is optional; with no init the CRT path is used.
Postcondition
Returns either a 16-byte-aligned pointer to a block of at least size bytes or NULL.
If the active runtime mode is DW_MODE_RUNTIME and an error callback is installed, the error callback is invoked with DW_DYNAMIC_MEMORY_ALLOC_NOT_ALLOWED before allocation proceeds (allocation is reported, not blocked).
On allocation failure (return value NULL), if an error callback is installed it is invoked with DW_DYNAMIC_MEMORY_BAD_ALLOC.
API Group
  • Init: Yes
  • Runtime: No
  • De-Init: No

◆ dwDynamicMemory_release()

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.

Precondition
Caller must ensure this function does not execute concurrently with dwDynamicMemory_malloc() or dwDynamicMemory_free() on any thread (external synchronization required).
All memory previously allocated through the user-defined callbacks installed by dwDynamicMemory_initialize() has already been released using those same callbacks (a memory block must be freed by its matching deallocator).
Postcondition
The malloc/free callbacks and userData are cleared (NULL); subsequent calls to dwDynamicMemory_malloc()/dwDynamicMemory_free() use the CRT path (posix_memalign() / free()).
The error callback and the runtime mode are unchanged.
API Group
  • Init: Yes
  • Runtime: No
  • De-Init: Yes

◆ dwDynamicMemory_setErrorCallback()

DWALLOC_API_PUBLIC void dwDynamicMemory_setErrorCallback ( dwDynamicMemoryErrorCallback  errorCallback,
void *const  userData 
)

Set error callback to be executed on an allocation/free during runtime mode.

Parameters
[in]errorCallbackCallback to be called on any error. May be NULL to disable reporting.
[in]userDataUser pointer to return back through the error callback
Precondition
Caller must ensure this function does not execute concurrently with dwDynamicMemory_malloc() or dwDynamicMemory_free() on any thread (external synchronization required).
Postcondition
Subsequent error events report through errorCallback with userData as the third argument:
  • DW_DYNAMIC_MEMORY_ALLOC_NOT_ALLOWED on malloc while in DW_MODE_RUNTIME,
  • DW_DYNAMIC_MEMORY_FREE_NOT_ALLOWED on free while in DW_MODE_RUNTIME,
  • DW_DYNAMIC_MEMORY_BAD_ALLOC on allocation failure (in any mode).
If errorCallback is NULL, error events are silently dropped.
API Group
  • Init: Yes
  • Runtime: Yes
  • De-Init: Yes

◆ dwDynamicMemory_setRuntimeMode()

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.

Parameters
[in]newModemode that you want to setup
Returns
false if given enum is ininvalid otherwise true
Precondition
Caller must ensure this function does not execute concurrently with dwDynamicMemory_malloc() or dwDynamicMemory_free() on any thread (external synchronization required).
Postcondition
On success (return true), the active runtime mode equals newMode and is observable via dwDynamicMemory_getRuntimeMode(). The behavior of subsequent malloc/free is governed by the new mode (see dwRuntimeMode).
On failure (return false, i.e. 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.
API Group
  • Init: Yes
  • Runtime: Yes
  • De-Init: Yes