Version
menu_open
link
Wwise SDK 2022.1.8
AkModule.h
Go to the documentation of this file.
1 /*******************************************************************************
2 The content of this file includes portions of the AUDIOKINETIC Wwise Technology
3 released in source code form as part of the SDK installer package.
4 
5 Commercial License Usage
6 
7 Licensees holding valid commercial licenses to the AUDIOKINETIC Wwise Technology
8 may use this file in accordance with the end user license agreement provided
9 with the software or, alternatively, in accordance with the terms contained in a
10 written agreement between you and Audiokinetic Inc.
11 
12 Apache License Usage
13 
14 Alternatively, this file may be used under the Apache License, Version 2.0 (the
15 "Apache License"); you may not use this file except in compliance with the
16 Apache License. You may obtain a copy of the Apache License at
17 http://www.apache.org/licenses/LICENSE-2.0.
18 
19 Unless required by applicable law or agreed to in writing, software distributed
20 under the Apache License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
21 OR CONDITIONS OF ANY KIND, either express or implied. See the Apache License for
22 the specific language governing permissions and limitations under the License.
23 
24  Copyright (c) 2023 Audiokinetic Inc.
25 *******************************************************************************/
26 
27 /// \file
28 /// Audiokinetic's definitions and factory of overridable Memory Manager module.
29 
30 #pragma once
31 
34 
35 /// \name Audiokinetic Memory Manager's implementation-specific definitions.
36 //@{
37 
39  );
40 
42  );
43 
45  );
46 
47 typedef void* ( AKSOUNDENGINE_CALL *AkMemMalloc ) (
48  AkMemPoolId poolId,
49  size_t uSize
50  );
51 
52 typedef void* ( AKSOUNDENGINE_CALL *AkMemMalign ) (
53  AkMemPoolId poolId,
54  size_t uSize,
55  AkUInt32 uAlignment
56  );
57 
58 typedef void* ( AKSOUNDENGINE_CALL *AkMemRealloc ) (
59  AkMemPoolId poolId,
60  void* pAddress,
61  size_t uSize
62  );
63 
64 
66  AkMemPoolId poolId,
67  void* pAddress,
68  size_t uSize,
69  AkUInt32 uAlignment
70  );
71 
72 typedef void ( AKSOUNDENGINE_CALL *AkMemFree ) (
73  AkMemPoolId poolId,
74  void* pAddress
75  );
76 
78  );
79 
81  AkMemPoolId poolId,
82  void* pAddress
83  );
84 
86  AkMemPoolId poolId,
87  size_t uSize,
88  void* pAddress,
89  char const* pszFile,
90  AkUInt32 uLine
91  );
92 
94  AkMemPoolId poolId,
95  size_t uSize,
96  AkUInt32 uAlignment,
97  void* pAddress,
98  char const* pszFile,
99  AkUInt32 uLine
100  );
101 
103  AkMemPoolId poolId,
104  void* pOldAddress,
105  size_t uSize,
106  void* pNewAddress,
107  char const* pszFile,
108  AkUInt32 uLine
109  );
110 
112  AkMemPoolId poolId,
113  void* pOldAddress,
114  size_t uSize,
115  AkUInt32 uAlignment,
116  void* pNewAddress,
117  char const* pszFile,
118  AkUInt32 uLine
119  );
120 
122  AkMemPoolId poolId,
123  void* pAddress
124  );
125 
126 typedef void* ( *AkMemAllocVM ) (
127  size_t size,
128  size_t* extra
129  );
130 
131 typedef void ( *AkMemFreeVM ) (
132  void* address,
133  size_t size,
134  size_t extra,
135  size_t release
136  );
137 
138 /// Initialization settings for the default implementation of the Memory Manager. For more details, see \ref memorymanager_init.
139 /// \sa AK::MemoryMgr
141 {
142  /// @name High-level memory allocation hooks. When not NULL, redirect allocations normally forwarded to rpmalloc.
143  //@{
144  AkMemInitForThread pfInitForThread; ///< (Optional) Thread-specific allocator initialization hook.
145  AkMemTermForThread pfTermForThread; ///< (Optional) Thread-specific allocator termination hook.
146  //AkMemTrimForThread pfTrimForThread; ///< (Optional) Thread-specific allocator "trimming" hook. Used to relinquish memory resources when threads enter a period of inactivity.
147  AkMemMalloc pfMalloc; ///< (Optional) Memory allocation hook.
148  AkMemMalign pfMalign; ///< (Optional) Memory allocation hook.
149  AkMemRealloc pfRealloc; ///< (Optional) Memory allocation hook.
150  AkMemReallocAligned pfReallocAligned; ///< (Optional) Memory allocation hook.
151  AkMemFree pfFree; ///< (Optional) Memory allocation hook.
152  AkMemTotalReservedMemorySize pfTotalReservedMemorySize; ///< (Optional) Memory allocation statistics hook.
153  AkMemSizeOfMemory pfSizeOfMemory; ///< (Optional) Memory allocation statistics hook.
154  //@}
155 
156  /// @name Configuration.
157  //@{
158  AkUInt64 uMemAllocationSizeLimit; ///< When non-zero, limits the total amount of virtual and device memory allocated by AK::MemoryMgr.
159  bool bUseDeviceMemAlways; ///< Use device memory for all allocations (on applicable platforms).
160  //@}
161 
162  /// @name Page allocation hooks, used by rpmalloc. Default to AKPLATFORM::AllocVM et al.
163  //@{
164  AkMemAllocVM pfAllocVM; ///< Virtual page allocation hook.
165  AkMemFreeVM pfFreeVM; ///< Virtual page allocation hook.
166  AkMemAllocVM pfAllocDevice; ///< Device page allocation hook.
167  AkMemFreeVM pfFreeDevice; ///< Device page allocation hook.
168  AkUInt32 uVMPageSize; ///< Virtual memory page size. Defaults to 0 which means auto-detect.
169  AkUInt32 uDevicePageSize; ///< Device memory page size. Defaults to 0 which means auto-detect.
170  AkUInt32 uMaxThreadLocalHeapAllocSize; ///< All memory allocations of sizes larger than this value will go to a global heap shared across all threads. Defaults to 0 which means all allocations go to a global heap.
171  //@}
172 
173  /// @name Memory allocation debugging.
174  //@{
175  AkMemDebugMalloc pfDebugMalloc; ///< (Optional) Memory allocation debugging hook. Used for tracking calls to pfMalloc.
176  AkMemDebugMalign pfDebugMalign; ///< (Optional) Memory allocation debugging hook. Used for tracking calls to pfMalign.
177  AkMemDebugRealloc pfDebugRealloc; ///< (Optional) Memory allocation debugging hook. Used for tracking calls to pfRealloc.
178  AkMemDebugReallocAligned pfDebugReallocAligned; ///< (Optional) Memory allocation debugging hook. Used for tracking calls to pfReallocAligned.
179  AkMemDebugFree pfDebugFree; ///< (Optional) Memory allocation debugging hook. Used for tracking calls to pfFree.
180  AkUInt32 uMemoryDebugLevel; ///< Default 0 disabled. 1 debug enabled. 2 stomp allocator enabled. 3 stomp allocator and debug enabled. User implementations may use multiple non-zero values to offer different features.
181  //@}
182 
183  // Moved to end-of-struct to maintain stability across 2022.1 modules.
184  AkMemTrimForThread pfTrimForThread; ///< (Optional) Thread-specific allocator "trimming" hook.
185 };
186 //@}
187 
188 namespace AK
189 {
190 
191 namespace MemoryMgr
192 {
193 
194 /// Initialize the default implementation of the Memory Manager.
195 /// \sa AK::MemoryMgr
197  AkMemSettings * in_pSettings ///< Memory manager initialization settings.
198  );
199 
200 /// Obtain the default initialization settings for the default implementation of the Memory Manager.
202  AkMemSettings & out_pMemSettings ///< Memory manager default initialization settings.
203  );
204 
205 }
206 
207 }
208 
209 #if defined AK_WIN || defined AK_LINUX || defined AK_SONY || defined AK_XBOX || defined AK_APPLE || defined AK_EMSCRIPTEN
210 #define AK_CRT_ALLOCATOR_SUPPORTED
211 #endif
212 
213 #ifdef AK_CRT_ALLOCATOR_SUPPORTED
214 namespace AK
215 {
216 
217 namespace MemoryMgr
218 {
219 
220 /// @name C runtime allocator functions for the default implementation of the Memory Manager.
221 //@{
222 
224 
226 
228 
230  AkMemPoolId poolId,
231  size_t uSize
232  );
233 
235  AkMemPoolId poolId,
236  size_t uSize,
237  AkUInt32 uAlignment
238  );
239 
241  AkMemPoolId poolId,
242  void* pAddress,
243  size_t uSize
244  );
245 
247  AkMemPoolId poolId,
248  void* pAddress,
249  size_t uSize,
250  AkUInt32 uAlignment
251  );
252 
254  AkMemPoolId poolId,
255  void* pAddress
256  );
257 
259 
261  AkMemPoolId poolID,
262  void* pAddress
263  );
264 
265 //@}
266 
267 }
268 
269 }
270 
271 #endif // AK_CRT_ALLOCATOR_SUPPORTED
272 
273 #if !defined AK_EMSCRIPTEN
274 #define AK_STOMP_ALLOCATOR_SUPPORTED
275 #endif
276 
277 #ifdef AK_STOMP_ALLOCATOR_SUPPORTED
278 
279 namespace AK
280 {
281 
282 namespace MemoryMgr
283 {
284 
285 /// @name Stomp allocator functions for the default implementation of the Memory Manager.
286 //@{
287 
289 
291 
293 
295  AkMemPoolId poolId,
296  size_t uSize
297  );
298 
300  AkMemPoolId poolId,
301  size_t uSize,
302  AkUInt32 uAlignment
303  );
304 
306  AkMemPoolId poolId,
307  void* pAddress,
308  size_t uSize
309  );
310 
312  AkMemPoolId poolId,
313  void* pAddress,
314  size_t uSize,
315  AkUInt32 uAlignment
316  );
317 
319  AkMemPoolId poolId,
320  void* pAddress
321  );
322 
324 
326  AkMemPoolId poolID,
327  void* pAddress
328  );
329 
330 //@}
331 
332 }
333 
334 }
335 #endif // AK_STOMP_ALLOCATOR_SUPPORTED
336 
337 namespace AK
338 {
339 
340 namespace MemoryMgr
341 {
342 
343 /// @name Debug tool hooks for the default implementation of the Memory Manager.
344 //@{
345 
347 
349 
351  AkMemPoolId poolId,
352  size_t uSize,
353  void* pAddress,
354  char const* pszFile,
355  AkUInt32 uLine
356  );
357 
359  AkMemPoolId poolId,
360  size_t uSize,
361  AkUInt32 uAlignment,
362  void* pAddress,
363  char const* pszFile,
364  AkUInt32 uLine
365  );
366 
368  AkMemPoolId poolId,
369  void* pOldAddress,
370  size_t uSize,
371  void* pNewAddress,
372  char const* pszFile,
373  AkUInt32 uLine
374  );
375 
377  AkMemPoolId poolId,
378  void* pOldAddress,
379  size_t uSize,
380  AkUInt32 uAlignment,
381  void* pNewAddress,
382  char const* pszFile,
383  AkUInt32 uLine
384  );
385 
387  AkMemPoolId poolId,
388  void* pAddress
389  );
390 
391 //@}
392 
393 }
394 
395 }
void(* AkMemDebugMalloc)(AkMemPoolId poolId, size_t uSize, void *pAddress, char const *pszFile, AkUInt32 uLine)
Definition: AkModule.h:85
AKSOUNDENGINE_API AKRESULT AkMemDebugToolInit()
Audiokinetic namespace.
AkMemTermForThread pfTermForThread
(Optional) Thread-specific allocator termination hook.
Definition: AkModule.h:145
void(* AkMemInitForThread)()
Definition: AkModule.h:38
AKSOUNDENGINE_API void AkMemDebugToolMalloc(AkMemPoolId poolId, size_t uSize, void *pAddress, char const *pszFile, AkUInt32 uLine)
AkUInt32 uMaxThreadLocalHeapAllocSize
All memory allocations of sizes larger than this value will go to a global heap shared across all thr...
Definition: AkModule.h:170
AkMemInitForThread pfInitForThread
(Optional) Thread-specific allocator initialization hook.
Definition: AkModule.h:144
AkMemFree pfFree
(Optional) Memory allocation hook.
Definition: AkModule.h:151
AkMemMalign pfMalign
(Optional) Memory allocation hook.
Definition: AkModule.h:148
AKSOUNDENGINE_API AKRESULT Init(AkMemSettings *in_pSettings)
AKSOUNDENGINE_API void AkStompAllocatorFree(AkMemPoolId poolId, void *pAddress)
AKSOUNDENGINE_API void AkCrtAllocatorInitForThread()
AKSOUNDENGINE_API void * AkStompAllocatorMalloc(AkMemPoolId poolId, size_t uSize)
#define AK_EXTERNAPIFUNC(_type, _name)
AkMemRealloc pfRealloc
(Optional) Memory allocation hook.
Definition: AkModule.h:149
AkMemFreeVM pfFreeVM
Virtual page allocation hook.
Definition: AkModule.h:165
AKRESULT
Standard function call result.
Definition: AkTypes.h:199
void *(* AkMemRealloc)(AkMemPoolId poolId, void *pAddress, size_t uSize)
Definition: AkModule.h:58
AKSOUNDENGINE_API void AkMemDebugToolFree(AkMemPoolId poolId, void *pAddress)
AkInt32 AkMemPoolId
Memory pool ID.
Definition: AkTypes.h:130
AkMemDebugRealloc pfDebugRealloc
(Optional) Memory allocation debugging hook. Used for tracking calls to pfRealloc.
Definition: AkModule.h:177
void(* AkMemDebugRealloc)(AkMemPoolId poolId, void *pOldAddress, size_t uSize, void *pNewAddress, char const *pszFile, AkUInt32 uLine)
Definition: AkModule.h:102
void *(* AkMemAllocVM)(size_t size, size_t *extra)
Definition: AkModule.h:126
AkMemDebugReallocAligned pfDebugReallocAligned
(Optional) Memory allocation debugging hook. Used for tracking calls to pfReallocAligned.
Definition: AkModule.h:178
void *(* AkMemReallocAligned)(AkMemPoolId poolId, void *pAddress, size_t uSize, AkUInt32 uAlignment)
Definition: AkModule.h:65
AKSOUNDENGINE_API void AkMemDebugToolTerm()
AKSOUNDENGINE_API void * AkCrtAllocatorMalign(AkMemPoolId poolId, size_t uSize, AkUInt32 uAlignment)
AkMemTrimForThread pfTrimForThread
(Optional) Thread-specific allocator "trimming" hook.
Definition: AkModule.h:184
AKSOUNDENGINE_API void AkMemDebugToolMalign(AkMemPoolId poolId, size_t uSize, AkUInt32 uAlignment, void *pAddress, char const *pszFile, AkUInt32 uLine)
void *(* AkMemMalloc)(AkMemPoolId poolId, size_t uSize)
Definition: AkModule.h:47
AKSOUNDENGINE_API void AkStompAllocatorTermForThread()
AKSOUNDENGINE_API void AkCrtAllocatorFree(AkMemPoolId poolId, void *pAddress)
AkMemReallocAligned pfReallocAligned
(Optional) Memory allocation hook.
Definition: AkModule.h:150
AkMemFreeVM pfFreeDevice
Device page allocation hook.
Definition: AkModule.h:167
size_t(* AkMemTotalReservedMemorySize)()
Definition: AkModule.h:77
AKSOUNDENGINE_API void * AkStompAllocatorRealloc(AkMemPoolId poolId, void *pAddress, size_t uSize)
AkMemAllocVM pfAllocVM
Virtual page allocation hook.
Definition: AkModule.h:164
AKSOUNDENGINE_API void * AkCrtAllocatorRealloc(AkMemPoolId poolId, void *pAddress, size_t uSize)
void(* AkMemTermForThread)()
Definition: AkModule.h:41
AkUInt64 uMemAllocationSizeLimit
When non-zero, limits the total amount of virtual and device memory allocated by AK::MemoryMgr.
Definition: AkModule.h:158
void(* AkMemDebugReallocAligned)(AkMemPoolId poolId, void *pOldAddress, size_t uSize, AkUInt32 uAlignment, void *pNewAddress, char const *pszFile, AkUInt32 uLine)
Definition: AkModule.h:111
AKSOUNDENGINE_API void AkStompAllocatorInitForThread()
AKSOUNDENGINE_API size_t AkCrtAllocatorSizeOfMemory(AkMemPoolId poolID, void *pAddress)
void(* AkMemTrimForThread)()
Definition: AkModule.h:44
void(* AkMemFree)(AkMemPoolId poolId, void *pAddress)
Definition: AkModule.h:72
AKSOUNDENGINE_API void AkMemDebugToolReallocAligned(AkMemPoolId poolId, void *pOldAddress, size_t uSize, AkUInt32 uAlignment, void *pNewAddress, char const *pszFile, AkUInt32 uLine)
AKSOUNDENGINE_API void GetDefaultSettings(AkMemSettings &out_pMemSettings)
Obtain the default initialization settings for the default implementation of the Memory Manager.
void *(* AkMemMalign)(AkMemPoolId poolId, size_t uSize, AkUInt32 uAlignment)
Definition: AkModule.h:52
AkUInt32 uMemoryDebugLevel
Default 0 disabled. 1 debug enabled. 2 stomp allocator enabled. 3 stomp allocator and debug enabled....
Definition: AkModule.h:180
AKSOUNDENGINE_API void * AkCrtAllocatorMalloc(AkMemPoolId poolId, size_t uSize)
#define AKSOUNDENGINE_CALL
Calling convention for the Wwise API.
Definition: AkTypes.h:114
AkUInt32 uDevicePageSize
Device memory page size. Defaults to 0 which means auto-detect.
Definition: AkModule.h:169
AkMemTotalReservedMemorySize pfTotalReservedMemorySize
(Optional) Memory allocation statistics hook.
Definition: AkModule.h:152
AKSOUNDENGINE_API void * AkStompAllocatorReallocAligned(AkMemPoolId poolId, void *pAddress, size_t uSize, AkUInt32 uAlignment)
AkMemMalloc pfMalloc
(Optional) Memory allocation hook.
Definition: AkModule.h:147
AKSOUNDENGINE_API void AkCrtAllocatorTermForThread()
AKSOUNDENGINE_API void * AkStompAllocatorMalign(AkMemPoolId poolId, size_t uSize, AkUInt32 uAlignment)
uint64_t AkUInt64
Unsigned 64-bit integer.
Definition: AkNumeralTypes.h:39
void(* AkMemFreeVM)(void *address, size_t size, size_t extra, size_t release)
Definition: AkModule.h:131
AKSOUNDENGINE_API void AkStompAllocatorTrimForThread()
AkMemDebugMalloc pfDebugMalloc
(Optional) Memory allocation debugging hook. Used for tracking calls to pfMalloc.
Definition: AkModule.h:175
AKSOUNDENGINE_API size_t AkStompAllocatorTotalReservedMemorySize()
uint32_t AkUInt32
Unsigned 32-bit integer.
Definition: AkNumeralTypes.h:38
size_t(* AkMemSizeOfMemory)(AkMemPoolId poolId, void *pAddress)
Definition: AkModule.h:80
AkUInt32 uVMPageSize
Virtual memory page size. Defaults to 0 which means auto-detect.
Definition: AkModule.h:168
void(* AkMemDebugMalign)(AkMemPoolId poolId, size_t uSize, AkUInt32 uAlignment, void *pAddress, char const *pszFile, AkUInt32 uLine)
Definition: AkModule.h:93
AKSOUNDENGINE_API size_t AkCrtAllocatorTotalReservedMemorySize()
AKSOUNDENGINE_API void AkCrtAllocatorTrimForThread()
void(* AkMemDebugFree)(AkMemPoolId poolId, void *pAddress)
Definition: AkModule.h:121
AkMemDebugFree pfDebugFree
(Optional) Memory allocation debugging hook. Used for tracking calls to pfFree.
Definition: AkModule.h:179
AkMemSizeOfMemory pfSizeOfMemory
(Optional) Memory allocation statistics hook.
Definition: AkModule.h:153
AkMemDebugMalign pfDebugMalign
(Optional) Memory allocation debugging hook. Used for tracking calls to pfMalign.
Definition: AkModule.h:176
AKSOUNDENGINE_API void AkMemDebugToolRealloc(AkMemPoolId poolId, void *pOldAddress, size_t uSize, void *pNewAddress, char const *pszFile, AkUInt32 uLine)
AKSOUNDENGINE_API void * AkCrtAllocatorReallocAligned(AkMemPoolId poolId, void *pAddress, size_t uSize, AkUInt32 uAlignment)
AKSOUNDENGINE_API size_t AkStompAllocatorSizeOfMemory(AkMemPoolId poolID, void *pAddress)
AkMemAllocVM pfAllocDevice
Device page allocation hook.
Definition: AkModule.h:166
bool bUseDeviceMemAlways
Use device memory for all allocations (on applicable platforms).
Definition: AkModule.h:159

Was this page helpful?

Need Support?

Questions? Problems? Need more info? Contact us, and we can help!

Visit our Support page

Tell us about your project. We're here to help.

Register your project and we'll help you get started with no strings attached!

Get started with Wwise