Table of Contents

Wwise SDK 2019.2.2
IAkPluginMemAlloc.h
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: <VERSION> Build: <BUILDNUMBER>
25  Copyright (c) <COPYRIGHTYEAR> 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 
34 #include <AK/SoundEngine/Common/AkTypes.h>
35 #include <AK/SoundEngine/Common/AkMemoryMgr.h> // For AK_MEMDEBUG
36 
37 namespace AK
38 {
39  /// Interface to memory allocation
40  /// \akwarning
41  /// The functions in this interface are not thread-safe, unless stated otherwise.
42  /// \endakwarning
43  ///
44  /// \akcaution SDK users should never call these function directly, but use memory allocation macros instead. \endakcaution
45  /// \sa
46  /// - \ref fx_memory_alloc
48  {
49  protected:
50  /// Virtual destructor on interface to avoid warnings.
51  virtual ~IAkPluginMemAlloc(){}
52 
53  public:
54 
55  /// Allocate memory.
56  /// \return A pointer to the newly-allocated memory.
57  /// \sa
58  /// - \ref fx_memory_alloc
59  virtual void * Malloc(
60  size_t in_uSize ///< Allocation size in bytes
61  ) = 0;
62 
63  /// Free allocated memory.
64  /// \sa
65  /// - \ref fx_memory_alloc
66  virtual void Free(
67  void * in_pMemAddress ///< Allocated memory start address
68  ) = 0;
69 
70  /// Allocate memory.
71  /// \return A pointer to the newly-allocated memory.
72  /// \sa
73  /// - \ref fx_memory_alloc
74  virtual void * Malign(
75  size_t in_uSize, ///< Allocation size in bytes
76  size_t in_uAlignment ///< Required alignment in bytes
77  ) = 0;
78 
79 #if defined (AK_MEMDEBUG)
80  /// Debug malloc.
81  /// \sa
82  /// - \ref fx_memory_alloc
83  virtual void * dMalloc(
84  size_t in_uSize, ///< Allocation size
85  const char* in_pszFile,///< Allocation file name (for tracking purposes)
86  AkUInt32 in_uLine ///< Allocation line number (for tracking purposes)
87  ) = 0;
88  /// Debug malign.
89  /// \sa
90  /// - \ref fx_memory_alloc
91  virtual void * dMalign(
92  size_t in_uSize, ///< Allocation size
93  size_t in_uAlign, ///< Allocation alignment
94  const char* in_pszFile,///< Allocation file name (for tracking purposes)
95  AkUInt32 in_uLine ///< Allocation line number (for tracking purposes)
96  ) = 0;
97 #endif
98  };
99 }
100 
101 // Memory allocation macros to be used by sound engine plug-ins.
102 #if defined (AK_MEMDEBUG)
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->dMalloc( size, szFile, ulLine );
107  }
108 
109  AkForceInline void operator</span> delete(void *, AK::IAkPluginMemAlloc *, const char*, AkUInt32) throw() {}
110 
111 #endif
112 
113  AkForceInline void * operator</span> new(size_t size,AK::IAkPluginMemAlloc * in_pAllocator) throw()
114  {
115  return in_pAllocator->Malloc( size );
116  }
117 
118  AkForceInline void operator</span> delete(void *,AK::IAkPluginMemAlloc *) throw() {}
119 
120 #if defined (AK_MEMDEBUG)
121  #define AK_PLUGIN_NEW(_allocator,_what) new((_allocator),__FILE__,__LINE__) _what
122  #define AK_PLUGIN_ALLOC(_allocator,_size) (_allocator)->dMalloc((_size),__FILE__,__LINE__)
123  #define AK_PLUGIN_ALLOC_ALIGN(_allocator,_size,_align) (_allocator)->dMalign((_size),(_align),__FILE__,__LINE__)
124 #else
125  /// Macro used to allocate objects.
126  /// \param _allocator Memory allocator interface.
127  /// \param _what Desired object type.
128  /// \return A pointer to the newly-allocated object.
129  /// \aknote Use AK_PLUGIN_DELETE() for memory allocated with this macro. \endaknote
130  /// \sa
131  /// - \ref fx_memory_alloc
132  /// - AK_PLUGIN_DELETE()
133  #define AK_PLUGIN_NEW(_allocator,_what) new(_allocator) _what
134  /// Macro used to allocate arrays of built-in types.
135  /// \param _allocator Memory allocator interface.
136  /// \param _size Requested size in bytes.
137  /// \return A void pointer to the the allocated memory.
138  /// \aknote Use AK_PLUGIN_FREE() for memory allocated with this macro. \endaknote
139  /// \sa
140  /// - \ref fx_memory_alloc
141  /// - AK_PLUGIN_FREE()
142  #define AK_PLUGIN_ALLOC(_allocator,_size) (_allocator)->Malloc((_size))
143  /// Macro used to allocate arrays of built-in types with alignment
144  /// \param _allocator Memory allocator interface.
145  /// \param _size Requested size in bytes.
146  /// \param _align Requested alignment of allocation
147  /// \return A void pointer to the the allocated memory.
148  /// \aknote Use AK_PLUGIN_FREE() for memory allocated with this macro. \endaknote
149  /// \sa
150  /// - \ref fx_memory_alloc
151  /// - AK_PLUGIN_FREE()
152  #define AK_PLUGIN_ALLOC_ALIGN(_allocator,_size,_align) (_allocator)->Malign((_size),(_align))
153 #endif
154 
155 /// Macro used to deallocate objects.
156 /// \param in_pAllocator Memory allocator interface.
157 /// \param in_pObject A pointer to the allocated object.
158 /// \sa
159 /// - \ref fx_memory_alloc
160 /// - AK_PLUGIN_NEW()
161 template <class T>
162 AkForceInline void AK_PLUGIN_DELETE( AK::IAkPluginMemAlloc * in_pAllocator, T * in_pObject )
163 {
164  if ( in_pObject )
165  {
166  in_pObject->~T();
167  in_pAllocator->Free( in_pObject );
168  }
169 }
170 
171 /// Macro used to deallocate arrays of built-in types.
172 /// \param _allocator Memory allocator interface.
173 /// \param _pvmem A void pointer to the allocated memory.
174 /// \sa
175 /// - \ref fx_memory_alloc
176 /// - AK_PLUGIN_ALLOC()
177 #define AK_PLUGIN_FREE(_allocator,_pvmem) (_allocator)->Free((_pvmem))
178 
179 #endif // _IAKPLUGINMEMALLOC_H_
Audiokinetic namespace.
virtual void * Malloc(size_t in_uSize)=0
virtual ~IAkPluginMemAlloc()
Virtual destructor on interface to avoid warnings.
virtual void Free(void *in_pMemAddress)=0
virtual void * Malign(size_t in_uSize, size_t in_uAlignment)=0