Version
menu_open
link
Wwise SDK 2022.1.4
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  //@}
171 
172  /// @name Memory allocation debugging.
173  //@{
174  AkMemDebugMalloc pfDebugMalloc; ///< (Optional) Memory allocation debugging hook. Used for tracking calls to pfMalloc.
175  AkMemDebugMalign pfDebugMalign; ///< (Optional) Memory allocation debugging hook. Used for tracking calls to pfMalign.
176  AkMemDebugRealloc pfDebugRealloc; ///< (Optional) Memory allocation debugging hook. Used for tracking calls to pfRealloc.
177  AkMemDebugReallocAligned pfDebugReallocAligned; ///< (Optional) Memory allocation debugging hook. Used for tracking calls to pfReallocAligned.
178  AkMemDebugFree pfDebugFree; ///< (Optional) Memory allocation debugging hook. Used for tracking calls to pfFree.
179  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.
180  //@}
181 
182  // Moved to end-of-struct to maintain stability across 2022.1 modules.
183  AkMemTrimForThread pfTrimForThread; ///< (Optional) Thread-specific allocator "trimming" hook.
184 };
185 //@}
186 
187 namespace AK
188 {
189 
190 namespace MemoryMgr
191 {
192 
193 /// Initialize the default implementation of the Memory Manager.
194 /// \sa AK::MemoryMgr
196  AkMemSettings * in_pSettings ///< Memory manager initialization settings.
197  );
198 
199 /// Obtain the default initialization settings for the default implementation of the Memory Manager.
201  AkMemSettings & out_pMemSettings ///< Memory manager default initialization settings.
202  );
203 
204 }
205 
206 }
207 
208 #if defined AK_WIN || defined AK_LINUX || defined AK_SONY || defined AK_XBOX || defined AK_APPLE || defined AK_EMSCRIPTEN
209 #define AK_CRT_ALLOCATOR_SUPPORTED
210 #endif
211 
212 #ifdef AK_CRT_ALLOCATOR_SUPPORTED
213 namespace AK
214 {
215 
216 namespace MemoryMgr
217 {
218 
219 /// @name C runtime allocator functions for the default implementation of the Memory Manager.
220 //@{
221 
223 
225 
227 
229  AkMemPoolId poolId,
230  size_t uSize
231  );
232 
234  AkMemPoolId poolId,
235  size_t uSize,
236  AkUInt32 uAlignment
237  );
238 
240  AkMemPoolId poolId,
241  void* pAddress,
242  size_t uSize
243  );
244 
246  AkMemPoolId poolId,
247  void* pAddress,
248  size_t uSize,
249  AkUInt32 uAlignment
250  );
251 
253  AkMemPoolId poolId,
254  void* pAddress
255  );
256 
258 
260  AkMemPoolId poolID,
261  void* pAddress
262  );
263 
264 //@}
265 
266 }
267 
268 }
269 
270 #endif // AK_CRT_ALLOCATOR_SUPPORTED
271 
272 #if !defined AK_EMSCRIPTEN
273 #define AK_STOMP_ALLOCATOR_SUPPORTED
274 #endif
275 
276 #ifdef AK_STOMP_ALLOCATOR_SUPPORTED
277 
278 namespace AK
279 {
280 
281 namespace MemoryMgr
282 {
283 
284 /// @name Stomp allocator functions for the default implementation of the Memory Manager.
285 //@{
286 
288 
290 
292 
294  AkMemPoolId poolId,
295  size_t uSize
296  );
297 
299  AkMemPoolId poolId,
300  size_t uSize,
301  AkUInt32 uAlignment
302  );
303 
305  AkMemPoolId poolId,
306  void* pAddress,
307  size_t uSize
308  );
309 
311  AkMemPoolId poolId,
312  void* pAddress,
313  size_t uSize,
314  AkUInt32 uAlignment
315  );
316 
318  AkMemPoolId poolId,
319  void* pAddress
320  );
321 
323 
325  AkMemPoolId poolID,
326  void* pAddress
327  );
328 
329 //@}
330 
331 }
332 
333 }
334 #endif // AK_STOMP_ALLOCATOR_SUPPORTED
335 
336 namespace AK
337 {
338 
339 namespace MemoryMgr
340 {
341 
342 /// @name Debug tool hooks for the default implementation of the Memory Manager.
343 //@{
344 
346 
348 
350  AkMemPoolId poolId,
351  size_t uSize,
352  void* pAddress,
353  char const* pszFile,
354  AkUInt32 uLine
355  );
356 
358  AkMemPoolId poolId,
359  size_t uSize,
360  AkUInt32 uAlignment,
361  void* pAddress,
362  char const* pszFile,
363  AkUInt32 uLine
364  );
365 
367  AkMemPoolId poolId,
368  void* pOldAddress,
369  size_t uSize,
370  void* pNewAddress,
371  char const* pszFile,
372  AkUInt32 uLine
373  );
374 
376  AkMemPoolId poolId,
377  void* pOldAddress,
378  size_t uSize,
379  AkUInt32 uAlignment,
380  void* pNewAddress,
381  char const* pszFile,
382  AkUInt32 uLine
383  );
384 
386  AkMemPoolId poolId,
387  void* pAddress
388  );
389 
390 //@}
391 
392 }
393 
394 }
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)
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:193
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:124
AkMemDebugRealloc pfDebugRealloc
(Optional) Memory allocation debugging hook. Used for tracking calls to pfRealloc.
Definition: AkModule.h:176
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:177
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:183
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:179
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:174
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:178
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:175
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