17 #ifndef INC_KY_Kernel_ListAlloc_H
18 #define INC_KY_Kernel_ListAlloc_H
53 template<
class T,
int PageSize,
class Allocator>
class ListAllocBase
57 typedef Allocator AllocatorType;
58 typedef ListAllocBase<T, PageSize, Allocator> SelfType;
63 ValueType Data[PageSize];
72 ListAllocBase(
void* p) :
75 NumElementsInPage(PageSize),
79 KY_COMPILER_ASSERT(
sizeof(T) >=
sizeof(T*));
86 NumElementsInPage(PageSize),
89 KY_COMPILER_ASSERT(
sizeof(T) >=
sizeof(T*));
98 void ClearAndRelease()
103 NumElementsInPage = PageSize;
107 UPInt GetNumBytes()
const
110 const PageType* page = FirstPage;
113 numBytes +=
sizeof(PageType);
122 Allocator::Construct(ret);
129 Allocator::Construct(ret, v);
134 T* AllocAlt(
const S& v)
136 ValueType* ret = allocate();
137 Allocator::ConstructAlt(ret, v);
141 void Free(T* element)
143 Allocator::Destruct(element);
144 ((NodeType*)element)->pNext = FirstEmptySlot;
145 FirstEmptySlot = (NodeType*)element;
150 ListAllocBase(
const SelfType&);
151 const SelfType& operator = (SelfType&);
157 T* ret = (T*)FirstEmptySlot;
158 FirstEmptySlot = FirstEmptySlot->pNext;
161 if (NumElementsInPage < PageSize)
163 return &LastPage->Data[NumElementsInPage++];
166 PageType* next = (PageType*)Allocator::Alloc(pHeapOrPtr,
sizeof(PageType), __FILE__, __LINE__);
169 LastPage->pNext = next;
173 NumElementsInPage = 1;
174 return &LastPage->Data[0];
177 inline void freeMem()
179 PageType* page = FirstPage;
182 PageType* next = page ->pNext;
183 Allocator::Free(page);
190 unsigned NumElementsInPage;
191 NodeType* FirstEmptySlot;
203 template<
class T,
int PageSize=127,
int SID=Stat_Default_Mem>
205 public ListAllocBase<T, PageSize, AllocatorGH_POD<T, SID> >
208 typedef ListAllocPOD<T, PageSize, SID> SelfType;
210 typedef AllocatorGH_POD<T, SID> AllocatorType;
220 template<
class T,
int PageSize=127,
int SID=Stat_Default_Mem>
222 public ListAllocBase<T, PageSize, AllocatorGH<T, SID> >
225 typedef ListAlloc<T, PageSize, SID> SelfType;
227 typedef AllocatorGH<T, SID> AllocatorType;
237 template<
class T,
int PageSize=127,
int SID=Stat_Default_Mem>
238 class ListAllocLH_POD :
239 public ListAllocBase<T, PageSize, AllocatorLH_POD<T, SID> >
242 typedef ListAllocLH_POD<T, PageSize, SID> SelfType;
244 typedef AllocatorLH_POD<T, SID> AllocatorType;
254 template<
class T,
int PageSize=127,
int SID=Stat_Default_Mem>
256 public ListAllocBase<T, PageSize, AllocatorLH<T, SID> >
259 typedef ListAllocLH<T, PageSize, SID> SelfType;
261 typedef AllocatorLH<T, SID> AllocatorType;
270 template<
class T,
int PageSize=127,
int SID=Stat_Default_Mem>
271 class ListAllocDH_POD :
272 public ListAllocBase<T, PageSize, AllocatorDH_POD<T, SID> >
275 typedef ListAllocDH_POD<T, PageSize, SID> SelfType;
277 typedef AllocatorDH_POD<T, SID> AllocatorType;
279 ListAllocDH_POD(
void* pHeap)
280 : ListAllocBase<T, PageSize, AllocatorDH_POD<T, SID> >(pHeap) {}
290 template<
class T,
int PageSize=127,
int SID=Stat_Default_Mem>
292 public ListAllocBase<T, PageSize, AllocatorDH<T, SID> >
295 typedef ListAllocDH<T, PageSize, SID> SelfType;
297 typedef AllocatorDH<T, SID> AllocatorType;
299 ListAllocDH(
void* pHeap)
300 : ListAllocBase<T, PageSize, AllocatorDH<T, SID> >(pHeap) {}
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17