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>
37 Stack() { TopPart = TopFreePart = NULL; UsedInTop = Num; SSize = 0; }
39 int Size()
const {
return SSize; }
55 template <
class Elem,
int Num>
61 if (TopFreePart == NULL)
67 TopFreePart = (aux = TopFreePart)->Prev;
77 template <
class Elem,
int Num>
83 TopPart = (aux = TopPart)->Prev;
84 aux->
Prev = TopFreePart;
89 return TopPart->
Elements[--UsedInTop];
92 template <
class Elem,
int Num>
96 while (TopPart != NULL)
98 TopPart = (aux = TopPart)->Prev;
101 while (TopFreePart != NULL)
103 TopFreePart = (aux = TopFreePart)->Prev;
110 template <
class Elem,
int Num>
119 template <
class Elem,
int Num>
140 template <
class Elem,
int Num>
148 template <
class Elem,
int Num>
165 template <
class Elem,
int Num>
169 if (UsedMem.Size() > 0)
171 return UsedMem.Pop();
173 if (AllocatedInLast == Num)
180 return &(Last->Elements[AllocatedInLast++]);
183 template <
class Elem,
int Num>
189 template <
class Elem,
int Num>
199 AllocatedInLast = Num;
203 template <
class Elem,
int Num>
207 mfem::Swap(AllocatedInLast, other.AllocatedInLast);
208 UsedMem.Swap(other.UsedMem);
211 template <
class Elem,
int Num>
size_t MemoryUsage() const
void Swap(Stack< Elem, Num > &other)
Swap the data in this stack with the data in other.
Stack()
Construct an empty stack.
size_t MemoryUsage() const
Return the number of bytes used by the stack.
StackPart< Elem, Num > * Prev
void Push(Elem E)
Push element 'E' on the stack.
Elem Pop()
Pop an element off the stack and return it.
void Swap(Array< T > &, Array< T > &)
void Swap(MemAlloc< Elem, Num > &other)
void Clear()
Clear the elements off the stack.
int Size() const
Return the number of elements on the stack.
MemAllocNode< Elem, Num > * Prev