gwnavruntime/containers/poolchunk.h Source File
Go to the documentation of this file.
28 KY_INLINE
void Delete(T* ptr) { Delete(GetIdxInChunk(ptr)); }
31 const T* Get(
KyUInt32 index)
const {
return ((T*)m_buffer) + index; }
32 T* Get(
KyUInt32 index) {
return ((T*)m_buffer) + index; }
34 KY_INLINE
bool IsFull()
const {
return (m_nbFreeSlots == 0); }
35 KY_INLINE
bool IsEmpty()
const {
return (m_nbFreeSlots == GetNbSlots()); }
37 KY_INLINE
bool IsPtrInChunk(
const T* ptr)
const {
return ((T*)m_buffer) <= ptr && ptr < (((T*)m_buffer) + m_nbTotalSlots); }
39 KY_INLINE
KyUInt32 GetNbSlots()
const {
return m_nbTotalSlots; }
40 KY_INLINE
KyUInt32 GetNbUsedSlots()
const {
return m_nbTotalSlots - m_nbFreeSlots; }
42 KyUInt32 GetIdxInChunk(
const T* ptr)
const {
return KyUInt32(ptr - (T*)m_buffer); }
44 bool SuperSlow_IsSlotFree(
KyUInt32 index)
const;
49 void SetNextFreeSlot(
KyUInt32 index,
KyUInt32 freeSlotIndex) { *((
KyUInt32*) (m_buffer + (
sizeof(T) * index))) = freeSlotIndex; }
64 PoolChunk<T>::PoolChunk(MemoryHeap* heap,
KyUInt32 slotCount,
KyUInt32 memStat) :
65 m_buffer((char*)KY_HEAP_ALLOC(heap, (sizeof(T) * slotCount), memStat)),
66 m_nbFreeSlots(slotCount),
67 m_nbTotalSlots(slotCount),
70 KY_DEBUG_ASSERTN(
sizeof (T) >= 4, (
"Type should be bigger to enable some functionalities"));
71 KY_DEBUG_ASSERTN(slotCount != 0, (
"Bad parameter"));
75 for (
KyUInt32 i = 0; i < slotCount; ++i)
76 SetNextFreeSlot(i, i + 1);
81 PoolChunk<T>::~PoolChunk()
83 if (IsEmpty() ==
false)
85 KY_LOG_WARNING((
"Bad usage of PoolChunk : you should call 'Delete' for each 'New'."));
94 KY_ASSERT(IsFull() ==
false);
96 const KyUInt32 index = GetFreeSlotAndMakeUsed();
104 KyUInt32 PoolChunk<T>::New(
const T& data)
106 KY_ASSERT(IsFull() ==
false);
108 const KyUInt32 index = GetFreeSlotAndMakeUsed();
116 void PoolChunk<T>::Delete(
KyUInt32 index)
118 KY_ASSERT(index < m_nbTotalSlots);
125 bool PoolChunk<T>::SuperSlow_IsSlotFree(
KyUInt32 index)
const
127 KyUInt32 freeSlotIdx = m_firstFreeSlot;
129 for (
KyUInt32 i = 0; i != m_nbFreeSlots; ++i)
131 if (freeSlotIdx == index)
133 freeSlotIdx = GetNextFreeSlot(freeSlotIdx);
140 KyUInt32 PoolChunk<T>::GetFreeSlotAndMakeUsed()
142 const KyUInt32 res = m_firstFreeSlot;
143 m_firstFreeSlot = GetNextFreeSlot(m_firstFreeSlot);
150 void PoolChunk<T>::MakeSlotFree(
KyUInt32 index)
152 SetNextFreeSlot(index, m_firstFreeSlot);
153 m_firstFreeSlot = index;
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:132
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17