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
00042 struct AkPlacementNewKey
00043 {
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 #ifndef AK_3DS
00058 AkForceInline void operator delete( void *, void *, const AkPlacementNewKey & ) throw() {}
00059 #endif
00060
00061
00062
00063
00064
00066 struct AkPoolNewKey
00067 {
00069 AkForceInline AkPoolNewKey(){}
00070 };
00071
00072
00073 #if defined (AK_MEMDEBUG)
00074 #define AkNew(_pool,_what) new((_pool),AkPoolNewKey(),__FILE__,__LINE__) _what
00075 #define AkAlloc(_pool,_size) (AK::MemoryMgr::dMalloc((_pool),_size,__FILE__,__LINE__))
00076 #define AkNew2(_ptr,_pool,_type,_what) { _ptr = (_type *) AK::MemoryMgr::dMalloc((_pool),sizeof(_type),__FILE__,__LINE__); if ( _ptr ) AkPlacementNew( _ptr ) _what; }
00077 #define AkMalign(_pool,_size,_align) (AK::MemoryMgr::dMalign((_pool),_size,_align, __FILE__,__LINE__))
00078 #define AkNewAligned(_pool,_what,_align) new((_pool),AkPoolNewKey(),(_align),__FILE__,__LINE__) _what
00079 #else
00080 #define AkNew(_pool,_what) new((_pool),AkPoolNewKey()) _what
00081 #define AkAlloc(_pool,_size) (AK::MemoryMgr::Malloc((_pool),_size))
00082 #define AkNew2(_ptr,_pool,_type,_what) { _ptr = (_type *) AK::MemoryMgr::Malloc((_pool),sizeof(_type)); if ( _ptr ) AkPlacementNew( _ptr ) _what; }
00083 #define AkMalign(_pool,_size,_align) (AK::MemoryMgr::Malign((_pool),_size,_align))
00084 #define AkNewAligned(_pool,_what,_align) new((_pool),AkPoolNewKey(),(_align)) _what
00085 #endif
00086
00087 #define AkFree(_pool,_pvmem) (AK::MemoryMgr::Free((_pool),(_pvmem)))
00088 #define AkFalign(_pool,_pvmem) (AK::MemoryMgr::Falign((_pool),(_pvmem)))
00089
00090 #if defined (AK_MEMDEBUG)
00091
00092 AkForceInline void * operator new(size_t size,AkMemPoolId in_PoolId,const AkPoolNewKey &,const char* szFile,AkUInt32 ulLine) throw()
00093 {
00094 return AK::MemoryMgr::dMalloc( in_PoolId, size, szFile, ulLine );
00095 }
00096
00097 AkForceInline void * operator new(size_t size,AkMemPoolId in_PoolId,const AkPoolNewKey &,AkUInt32 in_align,const char* szFile,AkUInt32 ulLine) throw()
00098 {
00099 return AK::MemoryMgr::dMalign( in_PoolId, size, in_align, szFile, ulLine );
00100 }
00101
00102 #ifndef AK_3DS
00103 AkForceInline void operator delete(void *,AkMemPoolId,const AkPoolNewKey &,const char*,AkUInt32) throw() {}
00104 AkForceInline void operator delete(void *,AkMemPoolId,const AkPoolNewKey &,AkUInt32,const char*,AkUInt32) throw() {}
00105 #endif
00106
00107 #else
00108
00109 AkForceInline void * operator new(size_t size,AkMemPoolId in_PoolId,const AkPoolNewKey &) throw()
00110 {
00111 return AK::MemoryMgr::Malloc( in_PoolId, size );
00112 }
00113
00114 AkForceInline void * operator new(size_t size,AkMemPoolId in_PoolId,const AkPoolNewKey &,AkUInt32 in_align) throw()
00115 {
00116 return AK::MemoryMgr::Malign( in_PoolId, size, in_align );
00117 }
00118
00119 #ifndef AK_3DS
00120 AkForceInline void operator delete(void *,AkMemPoolId,const AkPoolNewKey &) throw() {}
00121 AkForceInline void operator delete(void *,AkMemPoolId,const AkPoolNewKey &,AkUInt32) throw() {}
00122 #endif
00123
00124 #endif
00125
00126
00127
00128
00129
00130
00131 class CAkObject
00132 {
00133 public:
00135 virtual ~CAkObject( ) { }
00136 };
00137
00138 template <class T>
00139 AkForceInline void AkDelete( AkMemPoolId in_PoolId, T * in_pObject )
00140 {
00141 if ( in_pObject )
00142 {
00143 in_pObject->~T();
00144 AK::MemoryMgr::Free( in_PoolId, in_pObject );
00145 }
00146 }
00147
00148 template <class T>
00149 AkForceInline void AkDeleteAligned( AkMemPoolId in_PoolId, T * in_pObject )
00150 {
00151 if ( in_pObject )
00152 {
00153 in_pObject->~T();
00154 AK::MemoryMgr::Falign( in_PoolId, in_pObject );
00155 }
00156 }
00157
00158 #endif // _AK_OBJECT_H_