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

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