9 #ifndef GwNavGen_GrowingListPool_H
10 #define GwNavGen_GrowingListPool_H
21 template<
class T, KyUInt32 NbEl>
class GrowingListPool;
25 template<
class T, KyUInt32 NbEl = 8>
30 GrowingListNode() : m_next(
KY_NULL) {}
34 GrowingListNode<T, NbEl>* m_next;
39 template<
class T, KyUInt32 NbEl = 8>
44 typedef GrowingListPool<T, NbEl> Pool;
45 typedef GrowingListNode<T, NbEl> Node;
50 void Init(Pool* pool);
54 void PushBack(const T& value) { *GetNew() = value; }
56 KyInt32 Count()
const {
return m_count; }
58 void ToArray(T* values)
const;
70 template<
class T, KyUInt32 NbEl = 8>
75 typedef GrowingListNode<T, NbEl> Node;
76 typedef GrowingList<T, NbEl> List;
78 friend class GrowingList<T, NbEl>;
80 explicit GrowingListPool(MemoryHeap* heap,
KyUInt32 byteCountInChunk = 0) :
81 m_lists(heap, byteCountInChunk), m_nodes(heap, byteCountInChunk), m_elementCount(0), m_heap(heap) {}
85 KyUInt32 GetListChunkCount() {
return m_lists.GetChunkCount(); }
93 KyUInt32 ElementCount()
const {
return m_elementCount; }
98 GrowingPool<List> m_lists;
99 GrowingPool<Node> m_nodes;
105 template<
class T, KyUInt32 NbEl>
106 GrowingList<T, NbEl>::GrowingList()
112 template<
class T, KyUInt32 NbEl>
113 void GrowingList<T, NbEl>::Init(Pool* pool)
123 template<
class T, KyUInt32 NbEl>
124 void GrowingList<T, NbEl>::ToArray(T* values)
const
130 for (GrowingListNode<T, NbEl>* node = m_first; node != m_last; node = node->m_next)
132 for (
KyUInt32 i = 0; i < NbEl; ++i, ++idx)
133 values[idx] = node->m_values[i];
135 for (
KyUInt32 i = 0; i < m_countInLast; ++i, ++idx)
136 values[idx] = m_last->m_values[i];
140 template<
class T, KyUInt32 NbEl>
141 T* GrowingList<T, NbEl>::GetNew()
145 m_last = m_first = m_pool->GetNewNode();
147 else if (m_countInLast == NbEl)
149 GrowingListNode<T, NbEl>* newNode = m_pool->GetNewNode();
150 m_last->m_next = newNode;
156 KY_DEBUG_ASSERTN(m_countInLast >= 0 && m_countInLast < NbEl, (
"Can not get a new element"));
158 T* value = &m_last->m_values[m_countInLast];
162 ++m_pool->m_elementCount;
168 template<
class T, KyUInt32 NbEl>
169 GrowingList<T, NbEl>* GrowingListPool<T, NbEl>::GetNewList()
171 List* list = m_lists.GetNew();
177 template<
class T, KyUInt32 NbEl>
178 GrowingListNode<T, NbEl>* GrowingListPool<T, NbEl>::GetNewNode()
180 Node* node = m_nodes.GetNew();
185 template<
class T, KyUInt32 NbEl>
186 void GrowingListPool<T, NbEl>::Clear()
193 template<
class T, KyUInt32 NbEl>
194 void GrowingListPool<T, NbEl>::Release()
202 template<
class T, KyUInt32 NbEl>
203 KyUInt32 GrowingListPool<T, NbEl>::ByteCountAllocated()
const
205 return m_lists.ByteCountAllocated() + m_nodes.ByteCountAllocated();
int KyInt32
Type used internally to represent a 32-bit integer.
Definition: types.h:35
#define KY_NULL
Null value.
Definition: types.h:247
Definition: gamekitcrowddispersion.h:20
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36