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