Version
menu_open
link
Wwise SDK 2019.1.11
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  /// \warning The functions in this interface are not thread-safe, unless stated otherwise.
41  ///
42  /// \akcaution SDK users should never call these function directly, but use memory allocation macros instead. \endakcaution
43  /// \sa
44  /// - \ref fx_memory_alloc
46  {
47  protected:
48  /// Virtual destructor on interface to avoid warnings.
49  virtual ~IAkPluginMemAlloc(){}
50 
51  public:
52 
53  /// Allocate memory.
54  /// \return A pointer to the newly-allocated memory.
55  /// \sa
56  /// - \ref fx_memory_alloc
57  virtual void * Malloc(
58  size_t in_uSize ///< Allocation size in bytes
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 #if defined (AK_MEMDEBUG)
69  /// Debug malloc.
70  /// \sa
71  /// - \ref fx_memory_alloc
72  virtual void * dMalloc(
73  size_t in_uSize, ///< Allocation size
74  const char* in_pszFile,///< Allocation file name (for tracking purposes)
75  AkUInt32 in_uLine ///< Allocation line number (for tracking purposes)
76  ) = 0;
77 #endif
78  };
79 }
80 
81 // Memory allocation macros to be used by sound engine plug-ins.
82 #if defined (AK_MEMDEBUG)
83 
84  AkForceInline void * operator</span> new(size_t size,AK::IAkPluginMemAlloc * in_pAllocator,const char* szFile,AkUInt32 ulLine) throw()
85  {
86  return in_pAllocator->dMalloc( size, szFile, ulLine );
87  }
88 
89  AkForceInline void operator</span> delete(void *, AK::IAkPluginMemAlloc *, const char*, AkUInt32) throw() {}
90 
91 #endif
92 
93  AkForceInline void * operator</span> new(size_t size,AK::IAkPluginMemAlloc * in_pAllocator) throw()
94  {
95  return in_pAllocator->Malloc( size );
96  }
97 
98  AkForceInline void operator</span> delete(void *,AK::IAkPluginMemAlloc *) throw() {}
99 
100 #if defined (AK_MEMDEBUG)
101  #define AK_PLUGIN_NEW(_allocator,_what) new((_allocator),__FILE__,__LINE__) _what
102  #define AK_PLUGIN_ALLOC(_allocator,_size) (_allocator)->dMalloc((_size),__FILE__,__LINE__)
103 #else
104  /// Macro used to allocate objects.
105  /// \param _allocator Memory allocator interface.
106  /// \param _what Desired object type.
107  /// \return A pointer to the newly-allocated object.
108  /// \aknote Use AK_PLUGIN_DELETE() for memory allocated with this macro. \endaknote
109  /// \sa
110  /// - \ref fx_memory_alloc
111  /// - AK_PLUGIN_DELETE()
112  #define AK_PLUGIN_NEW(_allocator,_what) new(_allocator) _what
113  /// Macro used to allocate arrays of built-in types.
114  /// \param _allocator Memory allocator interface.
115  /// \param _size Requested size in bytes.
116  /// \return A void pointer to the the allocated memory.
117  /// \aknote Use AK_PLUGIN_FREE() for memory allocated with this macro. \endaknote
118  /// \sa
119  /// - \ref fx_memory_alloc
120  /// - AK_PLUGIN_FREE()
121  #define AK_PLUGIN_ALLOC(_allocator,_size) (_allocator)->Malloc((_size))
122 #endif
123 
124 /// Macro used to deallocate objects.
125 /// \param in_pAllocator Memory allocator interface.
126 /// \param in_pObject A pointer to the allocated object.
127 /// \sa
128 /// - \ref fx_memory_alloc
129 /// - AK_PLUGIN_NEW()
130 template <class T>
131 AkForceInline void AK_PLUGIN_DELETE( AK::IAkPluginMemAlloc * in_pAllocator, T * in_pObject )
132 {
133  if ( in_pObject )
134  {
135  in_pObject->~T();
136  in_pAllocator->Free( in_pObject );
137  }
138 }
139 
140 /// Macro used to deallocate arrays of built-in types.
141 /// \param _allocator Memory allocator interface.
142 /// \param _pvmem A void pointer to the allocated memory.
143 /// \sa
144 /// - \ref fx_memory_alloc
145 /// - AK_PLUGIN_ALLOC()
146 #define AK_PLUGIN_FREE(_allocator,_pvmem) (_allocator)->Free((_pvmem))
147 
148 #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

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