00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
00038
00039
00040
00041
00042 struct AkPlacementNewKey
00043 {
00044
00045 AkForceInline AkPlacementNewKey(){}
00046 };
00047
00048 AkForceInline void * operator new( size_t , void * memory, const AkPlacementNewKey & ) throw()
00049 {
00050 return memory;
00051 }
00052
00053 #define AkPlacementNew(_memory) ::new( _memory, AkPlacementNewKey() )
00054
00055
00056
00057 AkForceInline void operator delete( void *, void *, const AkPlacementNewKey & ) throw() {}
00058
00059
00060
00061
00062
00063
00064 struct AkPoolNewKey
00065 {
00066
00067 AkForceInline AkPoolNewKey(){}
00068 };
00069
00070
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_