Version
menu_open
link
Wwise SDK 2019.2.15
AkObject.h
Go to the documentation of this file.
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 #ifndef _AK_OBJECT_H_
29 #define _AK_OBJECT_H_
30 
32 
33 //-----------------------------------------------------------------------------
34 // Placement New definition. Use like this:
35 // AkPlacementNew( memorybuffer ) T(); // where T is your type constructor
36 //-----------------------------------------------------------------------------
37 
38 /// Unique structure identifier for AkPlacementNew.
40 {
41  /// ctor
43 };
44 
45 AkForceInline void * operator</span> new( size_t /*size*/, void * memory, const AkPlacementNewKey & /*key*/ ) throw()
46 {
47  return memory;
48 }
49 
50 #define AkPlacementNew(_memory) ::new( _memory, AkPlacementNewKey() )
51 
52 // Matching operator delete for AK placement new. This needs to be defined to avoid compiler warnings
53 // with projects built with exceptions enabled.
54 AkForceInline void operator</span> delete( void *, void *, const AkPlacementNewKey & ) throw() {}
55 
56 //-----------------------------------------------------------------------------
57 // Macros
58 //-----------------------------------------------------------------------------
59 
60 /// Unique structure identifier for AkNew.
61 struct AkPoolNewKey
62 {
63  /// ctor
65 };
66 
67 // Important: Use these macros with appropriate delete.
68 #if defined (AK_MEMDEBUG)
69  #define AkNew(_pool,_what) new((_pool),AkPoolNewKey(),__FILE__,__LINE__) _what
70  #define AkAlloc(_pool,_size) (AK::MemoryMgr::dMalloc((_pool),_size,__FILE__,__LINE__))
71  #define AkMalign(_pool,_size,_align) (AK::MemoryMgr::dMalign((_pool),_size,_align, __FILE__,__LINE__))
72  #define AkNewAligned(_pool,_what,_align) new((_pool),AkPoolNewKey(),(_align),__FILE__,__LINE__) _what
73  #define AkRealloc(_pool, _pvmem, _size) (AK::MemoryMgr::dRealloc((_pool),_pvmem,_size,__FILE__,__LINE__))
74 #else
75  #define AkNew(_pool,_what) new((_pool),AkPoolNewKey()) _what
76  #define AkAlloc(_pool,_size) (AK::MemoryMgr::Malloc((_pool),_size))
77  #define AkMalign(_pool,_size,_align) (AK::MemoryMgr::Malign((_pool),_size,_align))
78  #define AkNewAligned(_pool,_what,_align) new((_pool),AkPoolNewKey(),(_align)) _what
79  #define AkRealloc(_pool, _pvmem, _size) (AK::MemoryMgr::Realloc((_pool), _pvmem, _size))
80 #endif
81 
82 #define AkFree(_pool,_pvmem) (AK::MemoryMgr::Free((_pool),(_pvmem)))
83 #define AkFalign(_pool,_pvmem) (AK::MemoryMgr::Falign((_pool),(_pvmem)))
84 
85 #if defined (AK_MEMDEBUG)
86 
87  AkForceInline void * operator</span> new(size_t size,AkMemPoolId in_PoolId,const AkPoolNewKey &,const char* szFile,AkUInt32 ulLine) throw()
88  {
89  return AK::MemoryMgr::dMalloc( in_PoolId, size, szFile, ulLine );
90  }
91 
92  AkForceInline void * operator</span> new(size_t size,AkMemPoolId in_PoolId,const AkPoolNewKey &,AkUInt32 in_align,const char* szFile,AkUInt32 ulLine) throw()
93  {
94  return AK::MemoryMgr::dMalign( in_PoolId, size, in_align, szFile, ulLine );
95  }
96 
97  AkForceInline void operator</span> delete(void *,AkMemPoolId,const AkPoolNewKey &,const char*,AkUInt32) throw() {}
98  AkForceInline void operator</span> delete(void *,AkMemPoolId,const AkPoolNewKey &,AkUInt32,const char*,AkUInt32) throw() {}
99 
100 #else
101 
102  AkForceInline void * operator</span> new(size_t size,AkMemPoolId in_PoolId,const AkPoolNewKey &) throw()
103  {
104  return AK::MemoryMgr::Malloc( in_PoolId, size );
105  }
106 
107  AkForceInline void * operator</span> new(size_t size,AkMemPoolId in_PoolId,const AkPoolNewKey &,AkUInt32 in_align) throw()
108  {
109  return AK::MemoryMgr::Malign( in_PoolId, size, in_align );
110  }
111 
112  AkForceInline void operator</span> delete(void *,AkMemPoolId,const AkPoolNewKey &) throw() {}
113  AkForceInline void operator</span> delete(void *,AkMemPoolId,const AkPoolNewKey &,AkUInt32) throw() {}
114 
115 #endif
116 
117 template <class T>
118 AkForceInline void AkDelete( AkMemPoolId in_PoolId, T * in_pObject )
119 {
120  if ( in_pObject )
121  {
122  in_pObject->~T();
123  AK::MemoryMgr::Free( in_PoolId, in_pObject );
124  }
125 }
126 
127 template <class T>
128 AkForceInline void AkDeleteAligned( AkMemPoolId in_PoolId, T * in_pObject )
129 {
130  if ( in_pObject )
131  {
132  in_pObject->~T();
133  AK::MemoryMgr::Falign( in_PoolId, in_pObject );
134  }
135 }
136 
137 #endif // _AK_OBJECT_H_
AKSOUNDENGINE_API void Free(AkMemPoolId in_poolId, void *in_pMemAddress)
AKSOUNDENGINE_API void * Malloc(AkMemPoolId in_poolId, size_t in_uSize)
Unique structure identifier for AkNew.
Definition: AkObject.h:62
AkInt32 AkMemPoolId
Memory pool ID.
Definition: AkTypes.h:67
Unique structure identifier for AkPlacementNew.
Definition: AkObject.h:40
AkForceInline AkPlacementNewKey()
ctor
Definition: AkObject.h:42
AKSOUNDENGINE_API void Falign(AkMemPoolId in_poolId, void *in_pMemAddress)
AKSOUNDENGINE_API void * Malign(AkMemPoolId in_poolId, size_t in_uSize, AkUInt32 in_uAlignment)
AkForceInline void AkDeleteAligned(AkMemPoolId in_PoolId, T *in_pObject)
Definition: AkObject.h:128
AkForceInline void AkDelete(AkMemPoolId in_PoolId, T *in_pObject)
Definition: AkObject.h:118
uint32_t AkUInt32
Unsigned 32-bit integer.
Definition: AkTypes.h:85
#define AkForceInline
Definition: AkTypes.h:62
AkForceInline AkPoolNewKey()
ctor
Definition: AkObject.h:64

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