12 #ifndef MFEM_MEM_ALLOC
13 #define MFEM_MEM_ALLOC
15 #include "../config/config.hpp"
21 template <
class Elem,
int Num>
29 template <
class Elem,
int Num>
36 Stack() { TopPart = TopFreePart = NULL; UsedInTop = Num; SSize = 0; }
37 int Size() {
return SSize; }
44 template <
class Elem,
int Num>
50 if (TopFreePart == NULL)
56 TopFreePart = (aux = TopFreePart)->Prev;
66 template <
class Elem,
int Num>
72 TopPart = (aux = TopPart)->Prev;
73 aux->
Prev = TopFreePart;
78 return TopPart->
Elements[--UsedInTop];
81 template <
class Elem,
int Num>
85 while (TopPart != NULL)
87 TopPart = (aux = TopPart)->Prev;
90 while (TopFreePart != NULL)
92 TopFreePart = (aux = TopFreePart)->Prev;
100 template <
class Elem,
int Num>
108 template <
class Elem,
int Num>
123 template <
class Elem,
int Num>
127 if (UsedMem.Size() > 0)
129 return UsedMem.Pop();
131 if (AllocatedInLast == Num)
138 return &(Last->Elements[AllocatedInLast++]);
141 template <
class Elem,
int Num>
147 template <
class Elem,
int Num>
157 AllocatedInLast = Num;
StackPart< Elem, Num > * Prev
MemAllocNode< Elem, Num > * Prev