Go to the documentation of this file.
27 #ifndef _AKPOOLALLOCATOR_H
28 #define _AKPOOLALLOCATOR_H
36 #define AK_OBJECT_POOL_EXTRA_SAFETY
38 namespace UnitTest {
struct ObjectPoolHelper; }
42 template<AkMemID T_MEMID = AkMemID_Object>
47 inline static constexpr
void Lock() {}
48 inline static constexpr
void Unlock() {}
73 using AllocatorType::AllocatorType;
86 AKASSERT(!m_data &&
"ObjectPool is already initialized, call 'Term' before calling 'Init' again");
87 AKASSERT(count &&
"ObjectPool count must be greater than zero");
93 m_data =
reinterpret_cast<DataType*
>(AllocatorType::Alloc(count *
sizeof(
DataType)));
103 for (
SizeType i = 0; i < m_capacity - 1; i++)
104 m_data[i].next = i + 1;
114 AKASSERT(m_size == 0 &&
"Can't call Term() when some objects are still allocated");
141 DataType& data = m_data[m_freeList];
142 m_freeList = data.
next;
166 AKASSERT(data &&
"Deallocating null data");
170 AKASSERT((tdata >= m_data && tdata < m_data + m_capacity) &&
"Pointer address out of range");
171 if (tdata < m_data || tdata >= m_data + m_capacity)
175 AKASSERT(m_size &&
"Trying to deallocate when empty");
177 #ifdef AK_OBJECT_POOL_EXTRA_SAFETY
181 tdata->
next = m_freeList;
182 m_freeList = (
SizeType)(tdata - m_data);
192 for (
SizeType i = 0; i < m_capacity - 1; i++)
193 m_data[i].next = i + 1;
201 DataType* m_data =
nullptr;
208 inline bool IsAllocated(
SizeType index)
const
static constexpr SizeType kInvalidIndex
static constexpr void Unlock()
AKSOUNDENGINE_API void Free(AkMemPoolId in_poolId, void *in_pMemAddress)
AKRESULT
Standard function call result.
AK_NODISCARD ValueType * AllocateZeroFilled()
Initialize memory before returning.
AK_NODISCARD bool IsFull() const
AKRESULT Init(SizeType count)
@ AK_Success
The operation was successful.
ObjectPool(ObjectPool &&)=delete
@ AK_InvalidParameter
Something is not within bounds, check the documentation of the function returning this code.
AK_NODISCARD bool IsEmpty() const
uint8_t data[sizeof(ValueType)]
friend struct UnitTest::ObjectPoolHelper
#define AKASSERT(Condition)
AK_NODISCARD ValueType * Allocate()
AKRESULT Deallocate(ValueType *data)
AK_NODISCARD SizeType Size() const
ObjectPool(const ObjectPool &)=delete
AkForceInline void AkMemSet(void *pDest, AkInt32 iVal, AkUInt32 uSize)
Platform Independent Helper.
AK_NODISCARD SizeType Capacity() const
ObjectPool & operator=(const ObjectPool &)=delete
ObjectPool & operator=(ObjectPool &&)=delete
An object pool of N reusable objects with one allocation.
uint32_t AkUInt32
Unsigned 32-bit integer.
static constexpr void Lock()
@ AK_InsufficientMemory
Memory error.
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