DriveWorks SDK Reference
4.0.0 Release
For Test and Development only

src/dw/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 The NVIDIA<sup>&reg;</sup> DriveWorks memory management policy defines conventions intended to protect modules from memory corruption during runtime.
7 
8 @section core_memorymanagement Memory Management
9 
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
12 these conventions:
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.
20 
21 @subsection core_mm_customallocators Using Custom Memory Allocators
22 
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
25 memory allocations.
26 
27 @note SDK modules do perform dynamic allocations
28 only during initialization/creation time and perform no allocations at runtime.
29 
30 ```{.cpp}
31 #include <dw/core/DynamicMemory.h>
32 
33 // setup memory allocator
34 dwDynamicMemory_initialize(myMalloc, myFree, myContext);
35 
36 // initialize SDK
37 
38 dwInitialize(&sdkContext, DW_VERSION, &contextParams);
39 
40 ...
41 // do processing
42 ...
43 
44 // release SDK context
45 dwRelease(&sdkContext);
46 
47 // release memory allocator
48 dwDynamicMemory_release();
49 
50 ```
51 
52 @note As of this release, the user allocator is global. As such, it is not bound to a specific SDK context.
53 
54 @section core_threadsafety Thread Safety
55 
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.
60 
61 Applications are responsible for implementing thread-safety, if such is
62 required.
63 
64