Version
menu_open
link
Wwise SDK 2021.1.14
IAkPluginMemAlloc.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  Version: v2021.1.14 Build: 6590
25  Copyright (c) 2006-2023 Audiokinetic Inc.
26 *******************************************************************************/
27 
28 /// \file
29 /// Memory allocation macros for Wwise sound engine plug-ins.
30 
31 #ifndef _IAKPLUGINMEMALLOC_H_
32 #define _IAKPLUGINMEMALLOC_H_
33 
36 
37 namespace AK
38 {
39  /// Interface to memory allocation
40  /// \akcaution SDK users should never call these function directly, but use memory allocation macros instead. \endakcaution
41  /// \sa
42  /// - \ref fx_memory_alloc
44  {
45  protected:
46  /// Virtual destructor on interface to avoid warnings.
47  virtual ~IAkPluginMemAlloc(){}
48 
49  public:
50 
51  /// Allocate memory.
52  /// \return A pointer to the newly-allocated memory.
53  /// \sa
54  /// - \ref fx_memory_alloc
55  virtual void * Malloc(
56  size_t in_uSize, ///< Allocation size in bytes
57  const char* in_pszFile, ///< Allocation file name (for tracking purposes, unused in Release)
58  AkUInt32 in_uLine ///< Allocation line number (for tracking purposes, unused in Release)
59  ) = 0;
60 
61  /// Free allocated memory.
62  /// \sa
63  /// - \ref fx_memory_alloc
64  virtual void Free(
65  void * in_pMemAddress ///< Allocated memory start address
66  ) = 0;
67 
68  /// Allocate memory.
69  /// \return A pointer to the newly-allocated memory.
70  /// \sa
71  /// - \ref fx_memory_alloc
72  virtual void * Malign(
73  size_t in_uSize, ///< Allocation size in bytes
74  size_t in_uAlignment, ///< Required alignment in bytes
75  const char* in_pszFile, ///< Allocation file name (for tracking purposes, unused in Release)
76  AkUInt32 in_uLine ///< Allocation line number (for tracking purposes, unused in Release)
77  ) = 0;
78 
79  /// Reallocated memory.
80  /// \return A pointer to the reallocated memory.
81  /// \sa
82  /// - \ref fx_memory_alloc
83  virtual void * Realloc(
84  void * in_pMemAddress, ///< Allocated memory start address
85  size_t in_uSize, ///< Allocation size in bytes
86  const char* in_pszFile, ///< Allocation file name (for tracking purposes, unused in Release)
87  AkUInt32 in_uLine ///< Allocation line number (for tracking purposes, unused in Release)
88  ) = 0;
89 
90  /// Reallocated memory.
91  /// \return A pointer to the reallocated memory.
92  /// \sa
93  /// - \ref fx_memory_alloc
94  virtual void * ReallocAligned(
95  void * in_pMemAddress, ///< Allocated memory start address
96  size_t in_uSize, ///< Allocation size in bytes
97  size_t in_uAlignment, ///< Required alignment in bytes
98  const char* in_pszFile, ///< Allocation file name (for tracking purposes, unused in Release)
99  AkUInt32 in_uLine ///< Allocation line number (for tracking purposes, unused in Release)
100  ) = 0;
101  };
102 }
103 
104  AkForceInline void * operator</span> new( size_t size, AK::IAkPluginMemAlloc * in_pAllocator, const char * szFile, AkUInt32 ulLine) throw()
105  {
106  return in_pAllocator->Malloc( size, szFile, ulLine );
107  }
108 
109  AkForceInline void* operator</span> new(size_t size, AK::IAkPluginMemAlloc* in_pAllocator) throw()
110  {
111  return in_pAllocator->Malloc(size, NULL, 0);
112  }
113 
114  AkForceInline void operator</span> delete( void *, AK::IAkPluginMemAlloc *, const char *, AkUInt32 ) throw() {}
115  AkForceInline void operator</span> delete( void *, AK::IAkPluginMemAlloc * ) throw() {}
116 
117  /// Macro used to allocate objects.
118  /// \param _allocator Memory allocator interface.
119  /// \param _what Desired object type.
120  /// \return A pointer to the newly-allocated object.
121  /// \aknote Use AK_PLUGIN_DELETE() for memory allocated with this macro. \endaknote
122  /// \sa
123  /// - \ref fx_memory_alloc
124  /// - AK_PLUGIN_DELETE()
125  #define AK_PLUGIN_NEW( _allocator, _what ) new( ( _allocator ), __FILE__, __LINE__ ) _what
126 
127 
128  /// Macro used to allocate memory
129  /// \param _allocator Memory allocator interface.
130  /// \param _size Requested size in bytes.
131  /// \return A void pointer to the the allocated memory.
132  /// \aknote Use AK_PLUGIN_FREE() for memory allocated with this macro. \endaknote
133  /// \sa
134  /// - \ref fx_memory_alloc
135  /// - AK_PLUGIN_FREE()
136  #define AK_PLUGIN_ALLOC( _allocator, _size ) ( _allocator )->Malloc( ( _size ), __FILE__, __LINE__ )
137 
138  /// Macro used to allocate memory with an alignment
139  /// \param _allocator Memory allocator interface.
140  /// \param _size Requested size in bytes.
141  /// \param _align Requested alignment of allocation
142  /// \return A void pointer to the the allocated memory.
143  /// \aknote Use AK_PLUGIN_FREE() for memory allocated with this macro. \endaknote
144  /// \sa
145  /// - \ref fx_memory_alloc
146  /// - AK_PLUGIN_FREE()
147  #define AK_PLUGIN_ALLOC_ALIGN( _allocator, _size, _align ) ( _allocator )->Malign( ( _size ), ( _align ), __FILE__, __LINE__ )
148 
149  /// Macro used to reallocate memory
150  /// \param _allocator Memory allocator interface.
151  /// \param _pmem Start of allocated memory.
152  /// \param _size Requested size in bytes.
153  /// \return A void pointer to the the reallocated memory.
154  /// \aknote Use AK_PLUGIN_FREE() for memory allocated with this macro. \endaknote
155  /// \sa
156  /// - \ref fx_memory_alloc
157  /// - AK_PLUGIN_FREE()
158  #define AK_PLUGIN_REALLOC( _allocator, _pmem, _size ) ( _allocator )->Realloc( ( _pmem ), ( _size ), __FILE__, __LINE__ )
159 
160  /// Macro used to reallocate memory with an alignment
161  /// \param _allocator Memory allocator interface.
162  /// \param _pmem Start of allocated memory.
163  /// \param _size Requested size in bytes.
164  /// \param _align Requested alignment of allocation
165  /// \return A void pointer to the the reallocated memory.
166  /// \aknote Use AK_PLUGIN_FREE() for memory allocated with this macro. \endaknote
167  /// \sa
168  /// - \ref fx_memory_alloc
169  /// - AK_PLUGIN_FREE()
170  #define AK_PLUGIN_REALLOC_ALIGN( _allocator, _pmem, _size, _align ) ( _allocator )->ReallocAligned( ( _pmem ), ( _size ), ( _align ), __FILE__, __LINE__ )
171 
172 
173 /// Macro used to delete objects.
174 /// \param in_pAllocator Memory allocator interface.
175 /// \param in_pObject A pointer to the allocated object.
176 /// \sa
177 /// - \ref fx_memory_alloc
178 /// - AK_PLUGIN_NEW()
179 template <class T>
180 AkForceInline void AK_PLUGIN_DELETE( AK::IAkPluginMemAlloc * in_pAllocator, T * in_pObject )
181 {
182  if ( in_pObject )
183  {
184  in_pObject->~T();
185  in_pAllocator->Free( in_pObject );
186  }
187 }
188 
189 /// Macro used to free memory.
190 /// \param _allocator Memory allocator interface.
191 /// \param _pvmem A void pointer to the allocated memory.
192 /// \sa
193 /// - \ref fx_memory_alloc
194 /// - AK_PLUGIN_ALLOC()
195 #define AK_PLUGIN_FREE( _allocator, _pvmem ) ( _allocator )->Free( ( _pvmem ) )
196 
197 /// Allocator for plugin-friendly arrays (see AkArray).
198 /// Usage: Initialize the array with Init(AK::IAkPluginMemAlloc* in_pAllocator), passing it the memory allocator received from the host. Then use normally.
200 {
201 public:
203  AkForceInline void Init(AK::IAkPluginMemAlloc* in_pAllocator) { m_pAllocator = in_pAllocator; }
204 protected:
205  AkForceInline void* Alloc(size_t in_uSize) { return AK_PLUGIN_ALLOC(m_pAllocator, in_uSize); }
206  AkForceInline void* ReAlloc(void* in_pCurrent, size_t in_uOldSize, size_t in_uNewSize) { return AK_PLUGIN_REALLOC(m_pAllocator, in_pCurrent, in_uNewSize); }
207  AkForceInline void Free(void* in_pAddress) { AK_PLUGIN_FREE(m_pAllocator, in_pAddress); }
208  AkForceInline void TransferMem(void*& io_pDest, AkPluginArrayAllocator& in_src, void* in_pSrc)
209  {
210 #ifdef AKASSERT
211  AKASSERT(io_pDest == NULL);
212 #endif
213  io_pDest = in_pSrc;
214  m_pAllocator = in_src.GetAllocator();
215  }
217 private:
218  AK::IAkPluginMemAlloc* m_pAllocator;
219 };
220 
221 #endif // _IAKPLUGINMEMALLOC_H_
AkForceInline void AK_PLUGIN_DELETE(AK::IAkPluginMemAlloc *in_pAllocator, T *in_pObject)
AkForceInline void * Alloc(size_t in_uSize)
AkForceInline AK::IAkPluginMemAlloc * GetAllocator()
Audiokinetic namespace.
virtual void * Malloc(size_t in_uSize, const char *in_pszFile, AkUInt32 in_uLine)=0
#define NULL
Definition: AkTypes.h:47
AkForceInline void * ReAlloc(void *in_pCurrent, size_t in_uOldSize, size_t in_uNewSize)
AkForceInline void TransferMem(void *&io_pDest, AkPluginArrayAllocator &in_src, void *in_pSrc)
AkForceInline void Init(AK::IAkPluginMemAlloc *in_pAllocator)
#define AK_PLUGIN_FREE(_allocator, _pvmem)
#define AKASSERT(Condition)
Definition: AkAssert.h:76
virtual void * ReallocAligned(void *in_pMemAddress, size_t in_uSize, size_t in_uAlignment, const char *in_pszFile, AkUInt32 in_uLine)=0
AkForceInline AkPluginArrayAllocator()
#define AK_PLUGIN_ALLOC(_allocator, _size)
virtual void * Realloc(void *in_pMemAddress, size_t in_uSize, const char *in_pszFile, AkUInt32 in_uLine)=0
virtual ~IAkPluginMemAlloc()
Virtual destructor on interface to avoid warnings.
virtual void * Malign(size_t in_uSize, size_t in_uAlignment, const char *in_pszFile, AkUInt32 in_uLine)=0
virtual void Free(void *in_pMemAddress)=0
#define AK_PLUGIN_REALLOC(_allocator, _pmem, _size)
uint32_t AkUInt32
Unsigned 32-bit integer.
Definition: AkTypes.h:59
#define AkForceInline
Definition: AkTypes.h:60
AkForceInline void Free(void *in_pAddress)

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