19 template<
class T, KyUInt32 NbEl>
class GrowingListPool;
23 template<
class T, KyUInt32 NbEl = 8>
28 GrowingListNode() : m_next(
nullptr) {}
32 GrowingListNode<T, NbEl>* m_next;
37 template<
class T, KyUInt32 NbEl = 8>
42 typedef GrowingListPool<T, NbEl> Pool;
43 typedef GrowingListNode<T, NbEl> Node;
48 void Init(Pool* pool);
52 void PushBack(const T& value) { *GetNew() = value; }
54 KyInt32 Count()
const {
return m_count; }
56 void ToArray(T* values)
const;
68 template<
class T, KyUInt32 NbEl = 8>
73 typedef GrowingListNode<T, NbEl> Node;
74 typedef GrowingList<T, NbEl> List;
76 friend class GrowingList<T, NbEl>;
78 explicit GrowingListPool(MemoryHeap* heap,
KyUInt32 byteCountInChunk = 0) :
79 m_lists(heap, byteCountInChunk), m_nodes(heap, byteCountInChunk), m_elementCount(0), m_heap(heap) {}
83 KyUInt32 GetListChunkCount() {
return m_lists.GetChunkCount(); }
91 KyUInt32 ElementCount()
const {
return m_elementCount; }
96 GrowingPool<List> m_lists;
97 GrowingPool<Node> m_nodes;
103 template<
class T, KyUInt32 NbEl>
104 GrowingList<T, NbEl>::GrowingList()
110 template<
class T, KyUInt32 NbEl>
111 void GrowingList<T, NbEl>::Init(Pool* pool)
121 template<
class T, KyUInt32 NbEl>
122 void GrowingList<T, NbEl>::ToArray(T* values)
const
128 for (GrowingListNode<T, NbEl>* node = m_first; node != m_last; node = node->m_next)
130 for (
KyUInt32 i = 0; i < NbEl; ++i, ++idx)
131 values[idx] = node->m_values[i];
133 for (
KyUInt32 i = 0; i < m_countInLast; ++i, ++idx)
134 values[idx] = m_last->m_values[i];
138 template<
class T, KyUInt32 NbEl>
139 T* GrowingList<T, NbEl>::GetNew()
141 if (m_first ==
nullptr)
143 m_last = m_first = m_pool->GetNewNode();
145 else if (m_countInLast == NbEl)
147 GrowingListNode<T, NbEl>* newNode = m_pool->GetNewNode();
148 m_last->m_next = newNode;
154 KY_DEBUG_ASSERTN(m_countInLast >= 0 && m_countInLast < NbEl, (
"Can not get a new element"));
156 T* value = &m_last->m_values[m_countInLast];
160 ++m_pool->m_elementCount;
166 template<
class T, KyUInt32 NbEl>
167 GrowingList<T, NbEl>* GrowingListPool<T, NbEl>::GetNewList()
169 List* list = m_lists.GetNew();
175 template<
class T, KyUInt32 NbEl>
176 GrowingListNode<T, NbEl>* GrowingListPool<T, NbEl>::GetNewNode()
178 Node* node = m_nodes.GetNew();
183 template<
class T, KyUInt32 NbEl>
184 void GrowingListPool<T, NbEl>::Clear()
191 template<
class T, KyUInt32 NbEl>
192 void GrowingListPool<T, NbEl>::Release()
200 template<
class T, KyUInt32 NbEl>
201 KyUInt32 GrowingListPool<T, NbEl>::ByteCountAllocated()
const
203 return m_lists.ByteCountAllocated() + m_nodes.ByteCountAllocated();
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
std::int32_t KyInt32
int32_t
Definition: types.h:24