Version
menu

Wwise SDK 2024.1.6
AkMemoryArenaTypes.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) 2025 Audiokinetic Inc.
25 *******************************************************************************/
26 
27 /// \file
28 /// namespace for handling Wwise internal memory arena.
29 
30 #pragma once
31 
34 
35 typedef void* (AKSOUNDENGINE_CALL* AkAllocSpan) (
36  size_t in_uSize,
37  size_t* out_userData
38  );
39 typedef void (AKSOUNDENGINE_CALL* AkFreeSpan) (
40  void* in_pAddress,
41  size_t in_uSize,
42  size_t in_userData
43  );
44 
45 namespace AK
46 {
47  namespace MemoryArena
48  {
49  // the maximum size of the memory arena (provided externally for static code allocation, or other dynamically allocated heaps)
50  const AkUInt32 kMemoryArenaSize = 8192;
51 
52  // The overhead attached to 'huge' allocs, or spans allocated by the AkMemoryArena.
53  // Typically useful to slightly lower the size of ordinarily 'huge' allocations, to more precisely fit the page size, e.g.
54  // Malloc(pArena, 16 * 1024 * 1024 - kMemoryArenaSpanOverhead);
55  // will return an allocation that is exactly 16MiB in size, whereas,
56  // Malloc(pArena, 16 * 1024 * 1024);
57  // will return an allocation that is 18MiB in size, if MemoryArenaSettings::uPageSize is 2MiB
59 
61  {
62  bool bEnableSba; // Used to determine if the SbaHeap should be initialized and utilized at all. If disabled, all small allocs (size < kAllocSizeMedium) will go into the TlsfHeap and be treated as "Medium" allocs.
63  AkUInt32 uSbaInitSize; // the size of the initial allocation of memory for the small block allocator (SBA). This allocation will be made inside the main "tlsf" heap, and will always persist. Sub-allocations that fit in this range will have better fragmentation characteristics, and an overall reduction in memory overhead. This does not have to be a power-of-two.
64  AkUInt32 uSbaSpanSize; // the size of each span of memory for the SBA. Each span has a unique size class. Lower values can slightly increase the overhead of initializing SBA allocations, but can reduce overall memory reservation. This must be a power-of-two.
65  AkUInt32 uSbaMaximumUnusedSpans; // The maximum number of SBA spans that the system keeps in an unused state, and avoids freeing. Defaults to 1. Higher values do not increase the peak memory use, but do prevent unused memory from being freed, in order to reduce creation and destruction of SBA spans.
66 
67  AkUInt32 uTlsfInitSize; // the size of the initial span of memory requested for the main tlsf heap. This span will always persist. (does not have to be a power-of-two)
68  AkUInt32 uTlsfSpanSize; // when a memory allocation cannot fit in the main tlsf heap, and is a medium-sized allocation, new spans requested will be a multiple of this size (does not have to be a power-of-two)
69  AkUInt32 uTlsfLargeSpanSize; // when a memory allocation cannot fit in the main tlsf heap, and is a large-sized allocation, new spans requested will be a multiple of this size (does not have to be a power-of-two)
70  AkUInt32 uTlsfSpanOverhead; // the amount of allocation 'overhead' assumed for each span. When new spans for Tlsf are requested, this is subtracted from the size of the requested span, after multiplying the requested size up by uPageSize. Defaults to 128.
71  AkUInt32 uTlsfMaximumUnusedMediumSpans; // The maximum number of "medium spans" that the system keeps in an unused state, and avoids freeing. Defaults to 1. Higher values do not increase the peak memory use, but do prevent unused memory from being freed, in order to reduce creation and destruction of medium spans.
72  AkUInt32 uTlsfMaximumUnusedLargeSpans; // The maximum number of "large spans" that the system keeps in an unused state, and avoids freeing. Defaults to 1. Higher values do not increase the peak memory use, but do prevent unused memory from being freed, in order to reduce creation and destruction of large spans.
73 
74  AkUInt32 uAllocSizeLarge; // defines the minimum size for an allocation to qualify as "Large". Default to UINT_MAX, so that all large allocs are treated as Medium allocs. Large allocs go into best-fit searches, same as medium allocations, but will go to a separate list of secondary spans, distinct from "Medium" allocations
75  AkUInt32 uAllocSizeHuge; // defines the minimum size for an allocation to qualify as "Huge". Huge allocs always go into standalone spans even if there is space available in an existing span
76 
77  AkUInt32 uMemReservedLimit; // the limit on how much memory will be reserved by this arena. If a request for to reserve more memory is made that would go over this limit, a nullptr is returned. If set to zero, no limit is in place.
78 
79  AkAllocSpan fnMemAllocSpan; // called when the arena needs a new span of memory, including the initial one requested. Set to nullptr to disable initialization of the arena.
80  AkFreeSpan fnMemFreeSpan; // called when the arena is releasing a span of memory
81  };
82  }
83 }
Definition of data structures for AkAudioObject.
void *(* AkAllocSpan)(size_t in_uSize, size_t *out_userData)
const AkUInt32 kMemoryArenaSpanOverhead
#define AKSOUNDENGINE_CALL
Calling convention for the Wwise API.
Definition: AkTypes.h:118
const AkUInt32 kMemoryArenaSize
uint32_t AkUInt32
Unsigned 32-bit integer.
void(* AkFreeSpan)(void *in_pAddress, size_t in_uSize, size_t in_userData)

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