Go to the documentation of this file.
27 #ifndef _AKPOOLALLOCATOR_H
28 #define _AKPOOLALLOCATOR_H
36 #define AK_OBJECT_POOL_EXTRA_SAFETY
39 namespace UnitTest {
struct ObjectPoolHelper; }
44 template<AkMemID T_MEMID = AkMemID_Object>
49 inline static constexpr
void Lock() {}
50 inline static constexpr
void Unlock() {}
75 using AllocatorType::AllocatorType;
88 AKASSERT(!m_data &&
"ObjectPool is already initialized, call 'Term' before calling 'Init' again");
89 AKASSERT(count &&
"ObjectPool count must be greater than zero");
95 m_data =
reinterpret_cast<DataType*
>(AllocatorType::Alloc(count *
sizeof(
DataType)));
105 for (
SizeType i = 0; i < m_capacity - 1; i++)
106 m_data[i].next = i + 1;
116 AKASSERT(m_size == 0 &&
"Can't call Term() when some objects are still allocated");
143 DataType& data = m_data[m_freeList];
144 m_freeList = data.
next;
168 AKASSERT(data &&
"Deallocating null data");
172 AKASSERT((tdata >= m_data && tdata < m_data + m_capacity) &&
"Pointer address out of range");
173 if (tdata < m_data || tdata >= m_data + m_capacity)
177 AKASSERT(m_size &&
"Trying to deallocate when empty");
179 #ifdef AK_OBJECT_POOL_EXTRA_SAFETY
183 tdata->
next = m_freeList;
184 m_freeList = (
SizeType)(tdata - m_data);
194 for (
SizeType i = 0; i < m_capacity - 1; i++)
195 m_data[i].next = i + 1;
203 DataType* m_data =
nullptr;
210 inline bool IsAllocated(
SizeType index)
const
Definition of data structures for AkAudioObject.
static constexpr SizeType kInvalidIndex
static constexpr void Unlock()
AKSOUNDENGINE_API void Free(AkMemPoolId in_poolId, void *in_pMemAddress)
AK_NODISCARD ValueType * AllocateZeroFilled()
Initialize memory before returning.
AK_NODISCARD bool IsFull() const
AKRESULT Init(SizeType count)
ObjectPool(ObjectPool &&)=delete
AK_NODISCARD bool IsEmpty() const
uint8_t data[sizeof(ValueType)]
friend struct UnitTest::ObjectPoolHelper
#define AKASSERT(Condition)
AK_NODISCARD ValueType * Allocate()
@ AK_InsufficientMemory
Memory error.
AKRESULT Deallocate(ValueType *data)
AK_NODISCARD SizeType Size() const
ObjectPool(const ObjectPool &)=delete
AK_NODISCARD SizeType Capacity() const
ObjectPool & operator=(const ObjectPool &)=delete
ObjectPool & operator=(ObjectPool &&)=delete
An object pool of N reusable objects with one allocation.
@ AK_InvalidParameter
Something is not within bounds, check the documentation of the function returning this code.
uint32_t AkUInt32
Unsigned 32-bit integer.
static constexpr void Lock()
@ AK_Success
The operation was successful.
AkForceInline void AkMemSet(void *pDest, AkInt32 iVal, AkUInt32 uSize)
const ValueType & Data() const
Besoin d'aide ?
Des questions ? Des problèmes ? Besoin de plus d'informations ? Contactez-nous, nous pouvons vous aider !
Visitez notre page d'Aide
Décrivez-nous de votre projet. Nous sommes là pour vous aider.
Enregistrez votre projet et nous vous aiderons à démarrer sans aucune obligation !
Partir du bon pied avec Wwise