版本

menu_open

include/AK/Tools/Common/AkObject.h

浏览该文件的文档。
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 #ifndef _AK_OBJECT_H_
00029 #define _AK_OBJECT_H_
00030 
00031 #include <AK/SoundEngine/Common/AkMemoryMgr.h>
00032 
00033 extern AKSOUNDENGINE_API AkMemPoolId g_DefaultPoolId;
00034 extern AKSOUNDENGINE_API AkMemPoolId g_LEngineDefaultPoolId;
00035 
00036 //-----------------------------------------------------------------------------
00037 // Placement New definition. Use like this:
00038 // AkPlacementNew( memorybuffer ) T(); // where T is your type constructor
00039 //-----------------------------------------------------------------------------
00040 
00041 /// Unique structure identifier for AkPlacementNew. 
00042 struct AkPlacementNewKey 
00043 { 
00044     /// ctor 
00045     AkForceInline AkPlacementNewKey(){} 
00046 };
00047 
00048 AkForceInline void * operator new( size_t /*size*/, void * memory, const AkPlacementNewKey & /*key*/ ) throw()
00049 {
00050       return memory;
00051 }
00052 
00053 #define AkPlacementNew(_memory) ::new( _memory, AkPlacementNewKey() )
00054 
00055 // Matching operator delete for AK placement new. This needs to be defined to avoid compiler warnings
00056 // with projects built with exceptions enabled.
00057 AkForceInline void operator delete( void *, void *, const AkPlacementNewKey & ) throw() {}
00058 
00059 //-----------------------------------------------------------------------------
00060 // Macros
00061 //-----------------------------------------------------------------------------
00062 
00063 /// Unique structure identifier for AkNew. 
00064 struct AkPoolNewKey 
00065 { 
00066     /// ctor 
00067     AkForceInline AkPoolNewKey(){} 
00068 };
00069 
00070 // Important: Use these macros with appropriate delete.
00071 #if defined (AK_MEMDEBUG)
00072     #define AkNew(_pool,_what)              new((_pool),AkPoolNewKey(),__FILE__,__LINE__) _what
00073     #define AkAlloc(_pool,_size)            (AK::MemoryMgr::dMalloc((_pool),_size,__FILE__,__LINE__))
00074     #define AkNew2(_ptr,_pool,_type,_what)  { _ptr = (_type *) AK::MemoryMgr::dMalloc((_pool),sizeof(_type),__FILE__,__LINE__); if ( _ptr ) AkPlacementNew( _ptr ) _what; }
00075     #define AkMalign(_pool,_size,_align)    (AK::MemoryMgr::dMalign((_pool),_size,_align, __FILE__,__LINE__))
00076     #define AkNewAligned(_pool,_what,_align)    new((_pool),AkPoolNewKey(),(_align),__FILE__,__LINE__) _what
00077 #else
00078     #define AkNew(_pool,_what)              new((_pool),AkPoolNewKey()) _what
00079     #define AkAlloc(_pool,_size)            (AK::MemoryMgr::Malloc((_pool),_size))
00080     #define AkNew2(_ptr,_pool,_type,_what)  { _ptr = (_type *) AK::MemoryMgr::Malloc((_pool),sizeof(_type)); if ( _ptr ) AkPlacementNew( _ptr ) _what; }
00081     #define AkMalign(_pool,_size,_align)    (AK::MemoryMgr::Malign((_pool),_size,_align))
00082     #define AkNewAligned(_pool,_what,_align)    new((_pool),AkPoolNewKey(),(_align)) _what
00083 #endif
00084 
00085 #define AkFree(_pool,_pvmem)                (AK::MemoryMgr::Free((_pool),(_pvmem)))
00086 #define AkFalign(_pool,_pvmem)              (AK::MemoryMgr::Falign((_pool),(_pvmem)))
00087 
00088 #if defined (AK_MEMDEBUG)
00089 
00090     AkForceInline void * operator new(size_t size,AkMemPoolId in_PoolId,const AkPoolNewKey &,const char* szFile,AkUInt32 ulLine) throw()
00091     {
00092         return AK::MemoryMgr::dMalloc( in_PoolId, size, szFile, ulLine );
00093     }
00094 
00095     AkForceInline void * operator new(size_t size,AkMemPoolId in_PoolId,const AkPoolNewKey &,AkUInt32 in_align,const char* szFile,AkUInt32 ulLine) throw()
00096     {
00097         return AK::MemoryMgr::dMalign( in_PoolId, size, in_align, szFile, ulLine );
00098     }
00099     
00100     AkForceInline void operator delete(void *,AkMemPoolId,const AkPoolNewKey &,const char*,AkUInt32) throw() {}
00101     AkForceInline void operator delete(void *,AkMemPoolId,const AkPoolNewKey &,AkUInt32,const char*,AkUInt32) throw() {}
00102     
00103 #else
00104 
00105     AkForceInline void * operator new(size_t size,AkMemPoolId in_PoolId,const AkPoolNewKey &) throw()
00106     {
00107         return AK::MemoryMgr::Malloc( in_PoolId, size );
00108     }
00109 
00110     AkForceInline void * operator new(size_t size,AkMemPoolId in_PoolId,const AkPoolNewKey &,AkUInt32 in_align) throw()
00111     {
00112         return AK::MemoryMgr::Malign( in_PoolId, size, in_align );
00113     }
00114     
00115     AkForceInline void operator delete(void *,AkMemPoolId,const AkPoolNewKey &) throw() {}
00116     AkForceInline void operator delete(void *,AkMemPoolId,const AkPoolNewKey &,AkUInt32) throw() {}
00117 
00118 #endif
00119 
00120 template <class T>
00121 AkForceInline void AkDelete( AkMemPoolId in_PoolId, T * in_pObject )
00122 {
00123     if ( in_pObject )
00124     {
00125         in_pObject->~T();
00126         AK::MemoryMgr::Free( in_PoolId, in_pObject );
00127     }
00128 }
00129 
00130 template <class T>
00131 AkForceInline void AkDeleteAligned( AkMemPoolId in_PoolId, T * in_pObject )
00132 {
00133     if ( in_pObject )
00134     {
00135         in_pObject->~T();
00136         AK::MemoryMgr::Falign( in_PoolId, in_pObject );
00137     }
00138 }
00139 
00140 #endif // _AK_OBJECT_H_

此页面对您是否有帮助?

需要技术支持?

仍有疑问?或者问题?需要更多信息?欢迎联系我们,我们可以提供帮助!

查看我们的“技术支持”页面

介绍一下自己的项目。我们会竭力为您提供帮助。

来注册自己的项目,我们帮您快速入门,不带任何附加条件!

开始 Wwise 之旅