Version
menu_open
link

include/AK/SoundEngine/Common/IAkPluginMemAlloc.h

Go to the documentation of this file.
00001 /*******************************************************************************
00002 The content of this file includes portions of the AUDIOKINETIC Wwise Technology
00003 released in source code form as part of the SDK installer package.
00004 
00005 Commercial License Usage
00006 
00007 Licensees holding valid commercial licenses to the AUDIOKINETIC Wwise Technology
00008 may use this file in accordance with the end user license agreement provided 
00009 with the software or, alternatively, in accordance with the terms contained in a
00010 written agreement between you and Audiokinetic Inc.
00011 
00012 Apache License Usage
00013 
00014 Alternatively, this file may be used under the Apache License, Version 2.0 (the 
00015 "Apache License"); you may not use this file except in compliance with the 
00016 Apache License. You may obtain a copy of the Apache License at 
00017 http://www.apache.org/licenses/LICENSE-2.0.
00018 
00019 Unless required by applicable law or agreed to in writing, software distributed
00020 under the Apache License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
00021 OR CONDITIONS OF ANY KIND, either express or implied. See the Apache License for
00022 the specific language governing permissions and limitations under the License.
00023 
00024   Version: <VERSION>  Build: <BUILDNUMBER>
00025   Copyright (c) <COPYRIGHTYEAR> Audiokinetic Inc.
00026 *******************************************************************************/
00027 
00028 /// \file 
00029 /// Memory allocation macros for Wwise sound engine plug-ins. 
00030 
00031 #ifndef _IAKPLUGINMEMALLOC_H_
00032 #define _IAKPLUGINMEMALLOC_H_
00033 
00034 #include <AK/SoundEngine/Common/AkTypes.h>
00035 #include <AK/SoundEngine/Common/AkMemoryMgr.h> // For AK_MEMDEBUG
00036 
00037 namespace AK
00038 {
00039     /// Interface to memory allocation
00040     /// \warning The functions in this interface are not thread-safe, unless stated otherwise.
00041     ///
00042     /// \akcaution SDK users should never call these function directly, but use memory allocation macros instead. \endakcaution
00043     /// \sa 
00044     /// - \ref fx_memory_alloc
00045     class IAkPluginMemAlloc
00046     {
00047     protected:
00048         /// Virtual destructor on interface to avoid warnings.
00049         virtual ~IAkPluginMemAlloc(){}
00050 
00051     public:
00052         
00053         /// Allocate memory. 
00054         /// \return A pointer to the newly-allocated memory. 
00055         /// \sa 
00056         /// - \ref fx_memory_alloc
00057         virtual void * Malloc( 
00058             size_t in_uSize     ///< Allocation size in bytes
00059             ) = 0;
00060 
00061         /// Free allocated memory.
00062         /// \sa 
00063         /// - \ref fx_memory_alloc
00064         virtual void Free(
00065             void * in_pMemAddress   ///< Allocated memory start address
00066             ) = 0;
00067 
00068 #if defined (AK_MEMDEBUG)
00069         /// Debug malloc.
00070         /// \sa 
00071         /// - \ref fx_memory_alloc
00072         virtual void * dMalloc( 
00073             size_t   in_uSize,      ///< Allocation size
00074             const char*  in_pszFile,///< Allocation file name (for tracking purposes)
00075             AkUInt32 in_uLine       ///< Allocation line number (for tracking purposes)
00076             ) = 0;
00077 #endif
00078     };
00079 }
00080 
00081 // Memory allocation macros to be used by sound engine plug-ins.
00082 #if defined (AK_MEMDEBUG)
00083 
00084     AkForceInline void * operator new(size_t size,AK::IAkPluginMemAlloc * in_pAllocator,const char* szFile,AkUInt32 ulLine) throw()
00085     {
00086         return in_pAllocator->dMalloc( size, szFile, ulLine );
00087     }
00088 
00089     AkForceInline void operator delete(void *, AK::IAkPluginMemAlloc *, const char*, AkUInt32) throw() {}
00090     
00091 #endif
00092 
00093     AkForceInline void * operator new(size_t size,AK::IAkPluginMemAlloc * in_pAllocator) throw()
00094     {
00095         return in_pAllocator->Malloc( size );
00096     }
00097 
00098     AkForceInline void operator delete(void *,AK::IAkPluginMemAlloc *) throw() {}
00099 
00100 #if defined (AK_MEMDEBUG)
00101     #define AK_PLUGIN_NEW(_allocator,_what)             new((_allocator),__FILE__,__LINE__) _what
00102     #define AK_PLUGIN_ALLOC(_allocator,_size)           (_allocator)->dMalloc((_size),__FILE__,__LINE__)
00103 #else
00104     /// Macro used to allocate objects.
00105     /// \param _allocator Memory allocator interface.
00106     /// \param _what Desired object type. 
00107     /// \return A pointer to the newly-allocated object.
00108     /// \aknote Use AK_PLUGIN_DELETE() for memory allocated with this macro. \endaknote
00109     /// \sa
00110     /// - \ref fx_memory_alloc
00111     /// - AK_PLUGIN_DELETE()
00112     #define AK_PLUGIN_NEW(_allocator,_what)             new(_allocator) _what
00113     /// Macro used to allocate arrays of built-in types.
00114     /// \param _allocator Memory allocator interface.
00115     /// \param _size Requested size in bytes.
00116     /// \return A void pointer to the the allocated memory.
00117     /// \aknote Use AK_PLUGIN_FREE() for memory allocated with this macro. \endaknote
00118     /// \sa
00119     /// - \ref fx_memory_alloc
00120     /// - AK_PLUGIN_FREE()
00121     #define AK_PLUGIN_ALLOC(_allocator,_size)           (_allocator)->Malloc((_size))
00122 #endif
00123 
00124 /// Macro used to deallocate objects.
00125 /// \param in_pAllocator Memory allocator interface.
00126 /// \param in_pObject A pointer to the allocated object.
00127 /// \sa
00128 /// - \ref fx_memory_alloc
00129 /// - AK_PLUGIN_NEW()
00130 template <class T>
00131 AkForceInline void AK_PLUGIN_DELETE( AK::IAkPluginMemAlloc * in_pAllocator, T * in_pObject )      
00132 {
00133     if ( in_pObject )
00134     {
00135         in_pObject->~T();
00136         in_pAllocator->Free( in_pObject );
00137     }
00138 }
00139 
00140 /// Macro used to deallocate arrays of built-in types.
00141 /// \param _allocator Memory allocator interface.
00142 /// \param _pvmem A void pointer to the allocated memory.
00143 /// \sa
00144 /// - \ref fx_memory_alloc
00145 /// - AK_PLUGIN_ALLOC()
00146 #define AK_PLUGIN_FREE(_allocator,_pvmem)       (_allocator)->Free((_pvmem))
00147 
00148 #endif // _IAKPLUGINMEMALLOC_H_

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