DriveWorks SDK Reference
3.0.4260 Release
For Test and Development only

core/docs/usecase3.md
Go to the documentation of this file.
1 # Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved.
2 
3 @page core_usecase3 Memory Management Policies and Multithreading
4 @tableofcontents
5 
6 @note SW Release Applicability: This tutorial is applicable to modules in both **NVIDIA DriveWorks** and **NVIDIA DRIVE Software** releases.
7 
8 The NVIDIA<sup>&reg;</sup> DriveWorks memory management policy defines conventions intended to protect modules from memory corruption during runtime.
9 
10 @section core_memorymanagement Memory Management
11 
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
14 these conventions:
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.
22 
23 @subsection core_mm_customallocators Using Custom Memory Allocators
24 
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
27 memory allocations.
28 
29 @note SDK modules do perform dynamic allocations
30 only during initialization/creation time and perform no allocations at runtime.
31 
32 ```{.cpp}
33 #include <dw/core/DynamicMemory.h>
34 
35 // setup memory allocator
36 dwDynamicMemory_initialize(myMalloc, myFree, myContext);
37 
38 // initialize SDK
39 
40 dwInitialize(&sdkContext, DW_VERSION, &contextParams);
41 
42 ...
43 // do processing
44 ...
45 
46 // release SDK context
47 dwRelease(&sdkContext);
48 
49 // release memory allocator
50 dwDynamicMemory_release();
51 
52 ```
53 
54 @note As of this release, the user allocator is global. As such, it is not bound to a specific SDK context.
55 
56 @section core_threadsafety Thread Safety
57 
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.
62 
63 Applications are responsible for implementing thread-safety, if such is
64 required.
65 
66