Version

menu_open
Wwise SDK 2024.1.4
IAkPluginTempAlloc.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 /// Plug-in interface for temp-alloc systems
29 
30 #pragma once
31 
34 
35 namespace AK
36 {
37 
38 /// Interface for performing extremely-fast zero-fragmentation temporary allocations,
39 /// e.g. allocations that exist for one or two ticks, or allocations that exist for a single stack frame.
40 /// These use the existing TempAlloc infrastructure in the core soundengine, whose behaviour and allocation
41 /// characteristics are defined in the MemoryMgr initialization settings.
42 ///
43 /// For temporary allocations, types and lifetimes can be specified for mallocations -- or reallocs.
44 /// These allocations will only persist for the given soundengine tick (Lifetime_CurrentTick) and be destroyed
45 /// at the beginning of the next tick, or will persist for two soundengine ticks.
46 ///
47 /// For bookmark allocations, you need to mark the start of a bookmark-allocation Region and perform allocations
48 /// that persist until the bookmark-allocation region is closed. A struct, "PluginBookmarkAllocRegion" has
49 /// been provided to help with that.
50 ///
51 /// Because these allocations are guaranteed to be destroyed collectively and simultaneously as a part
52 /// of their respective system, there is no fragmentation incurred by this, and no 'free' function is available.
53 /// Also, these allocations are also extremely fast, with no multi-threading contention in most cases, and
54 /// the total overhead of each alloc measured on the order of dozens of cycles.
55 ///
56 /// \sa
57 /// - \ref goingfurther_optimizingmempools_bookmarkalloc
58 
60 {
61 protected:
63 public:
64 
65  // Returns an IAkPluginMemAlloc interface to perform temp allocations for the current Audio Render tick
66  // This is static for the duration of the process, so it can be cached once during init.
67  // Note that this interface is provided only for convenience with other systems; the "Free" operation in
68  // this interface is a no-op, and instead all memory is released at the end of the current audioRender tick.
70 
71  // Returns an IAkPluginMemAlloc interface to perform temp allocations for the current and next Audio Render tick
72  // This is static for the duration of the process, so it can be cached once during init.
73  // Note that this interface is provided only for convenience with other systems; the "Free" operation in
74  // this interface is a no-op, and instead all memory is released at the end of the next audioRender tick.
76 
77  // Returns an IAkPluginMemAlloc interface to perform 'bookmark' allocations.
78  // This is static for the duration of the process, so it can be cached once during init.
79  // Note that this interface is provided only for convenience with other systems; the "Free" operation in
80  // this interface is a no-op, and instead all memory is released at the end of the BookmarkAlloc Region
82 
83 private:
85 
86  // Call to mark the start of a bookmark alloc region. This must be called before any usage of the BookmarkAlloc memalloc interface.
87  // The bookmark pointer returned must be used in the equivalent call to EndBookmarkAllocRegion.
88  // This should only be used by the PluginBookmarkAllocRegion helper struct, below.
89  virtual void* BeginBookmarkAllocRegion() = 0;
90 
91  // Call to mark the end of a bookmark alloc region. Rewinds the stack usage back to where BeginBookmarkAllocRegion started
92  // This must be called for each call to BeginBookmarkAllocRegion.
93  // This should only be used by the PluginBookmarkAllocRegion helper struct, below.
94  virtual void EndBookmarkAllocRegion(void* in_pBookmark) = 0;
95 };
96 
97 // Helper struct to be used for performing any bookmark allocations.
98 // One of these must be instantiated before any usage of the BookmarkAlloc IAkPluginMemAlloc interface.
99 // Automatically rewinds the bookmarkAlloc memory back to the point where this was instantiated, when this leaves the scope.
101 {
103  {
104  m_pTempAlloc = in_pTempAlloc;
105  m_pBookmark = in_pTempAlloc->BeginBookmarkAllocRegion();
106  }
108  {
109  EndRegion();
110  }
111  void EndRegion()
112  {
113  m_pTempAlloc->EndBookmarkAllocRegion(m_pBookmark);
114  m_pBookmark = nullptr;
115  }
116 private:
117  void* m_pBookmark;
118  IAkPluginServiceTempAlloc* m_pTempAlloc;
119 };
120 
121 #define AK_GET_PLUGIN_SERVICE_TEMPALLOC(plugin_ctx) static_cast<AK::IAkPluginServiceTempAlloc*>(plugin_ctx->GetPluginService(AK::PluginServiceType_TempAlloc))
122 
123 } // namespace AK
virtual IAkPluginMemAlloc * GetTempAllocAudioRenderDouble()=0
Definition of data structures for AkAudioObject.
Common interface for plug-in services accessed through the global plug-in context.
Definition: IAkPlugin.h:1357
virtual IAkPluginMemAlloc * GetTempAllocAudioRenderCurrent()=0
PluginBookmarkAllocRegion(IAkPluginServiceTempAlloc *in_pTempAlloc)
virtual IAkPluginMemAlloc * GetBookmarkAlloc()=0

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