1 # Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved.
3 @page core_usecase3 Memory Management Policies and Multithreading
6 The NVIDIA<sup>®</sup> DriveWorks memory management policy defines conventions intended to protect modules from memory corruption during runtime.
8 @section core_memorymanagement Memory Management
10 For modules that require memory, the preferred method is static allocation (on
11 the stack). When that is not possible, memory allocation is controlled with
13 - During initialization/creation, modules use a _memory allocator_ to
14 dynamically allocate memory (on the heap). DriveWorks provides a default memory
15 allocator; however, you can also supply your own custom memory allocator. See
16 @ref core_mm_customallocators (below) and @ref core_memory_group.
17 - Memory allocator APIs allocate dynamic memory only during initialization time (before
18 runtime mode begins). With this restriction, dynamic memory allocation provides
19 similar protections to static memory allocation.
21 @subsection core_mm_customallocators Using Custom Memory Allocators
23 Before initializing a context, you can pass an instance of a custom memory
24 allocator to the SDK. The SDK then uses the memory allocator to perform dynamic
27 @note SDK modules do perform dynamic allocations
28 only during initialization/creation time and perform no allocations at runtime.
31 #include <dw/core/DynamicMemory.h>
33 // setup memory allocator
34 dwDynamicMemory_initialize(myMalloc, myFree, myContext);
38 dwInitialize(&sdkContext, DW_VERSION, &contextParams);
44 // release SDK context
45 dwRelease(&sdkContext);
47 // release memory allocator
48 dwDynamicMemory_release();
52 @note As of this release, the user allocator is global. As such, it is not bound to a specific SDK context.
54 @section core_threadsafety Thread Safety
56 Currently, the methods that DriveWorks modules expose do not follow any thread-
57 safety paradigm. To avoid the overhead of memory locks, DriveWorks methods are
58 considered to be non-thread safe. The exceptions are methods with documentation
59 that explicitly indicate a thread-safe implementation.
61 Applications are responsible for implementing thread-safety, if such is