56 template
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");
90 AKASSERT(count kInvalidIndex &&
"ObjectPool count is above SizeType's maximum capacity");
95 m_data =
reinterpret_castDataType*>(AllocatorType::Alloc(count * sizeof(DataType)));
105 for (
SizeType i = 0; 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 "Pointer address out of range");
173 if (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
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