12 #ifndef MFEM_MEM_ALLOC
13 #define MFEM_MEM_ALLOC
15 #include "../config/config.hpp"
20 template <
class Elem,
int Num>
28 template <
class Elem,
int Num>
35 Stack() { TopPart = TopFreePart = NULL; UsedInTop = Num; SSize = 0; };
36 int Size() {
return SSize; };
43 template <
class Elem,
int Num>
49 if (TopFreePart == NULL)
52 TopFreePart = (aux = TopFreePart)->Prev;
61 template <
class Elem,
int Num>
67 TopPart = (aux = TopPart)->Prev;
68 aux->
Prev = TopFreePart;
73 return TopPart->
Elements[--UsedInTop];
76 template <
class Elem,
int Num>
80 while (TopPart != NULL)
82 TopPart = (aux = TopPart)->Prev;
85 while (TopFreePart != NULL)
87 TopFreePart = (aux = TopFreePart)->Prev;
95 template <
class Elem,
int Num>
103 template <
class Elem,
int Num>
111 MemAlloc() { Last = NULL; AllocatedInLast = Num; };
118 template <
class Elem,
int Num>
122 if (UsedMem.Size() > 0)
123 return UsedMem.Pop();
124 if (AllocatedInLast == Num)
131 return &(Last->Elements[AllocatedInLast++]);
134 template <
class Elem,
int Num>
140 template <
class Elem,
int Num>
150 AllocatedInLast = Num;
StackPart< Elem, Num > * Prev
MemAllocNode< Elem, Num > * Prev