58 T *
alloc(
size_t size);
94 using byte_t =
unsigned char;
101 size_t mNumAllocs{0u};
102 byte_t *mData{
nullptr};
121 const size_t range = size *
sizeof(T) +
sizeof(Header);
122 const size_t limit = mTop + range;
123 if (limit > mCapacity) {
128 Header *header = (Header *)(&mData[mTop]);
129 header->mSize = size *
sizeof(T);
130 mTop +=
sizeof(Header);
133 T *ptr = (T *)(&mData[mTop]);
134 mTop += header->mSize;
142 if (
nullptr == ptr) {
147 byte_t *tmp = (byte_t *)ptr;
148 tmp = tmp -
sizeof(Header);
149 Header *head = (Header *)tmp;
150 const size_t allocSize = head->mSize;
154 mTop -=
sizeof(Header);
162 if (size > mCapacity) {
164 mCapacity = size *
sizeof(T);
165 mData =
new byte_t[mCapacity];
196 return (mCapacity - mTop);
202 allocs +=
"Number allocations = ";
203 allocs += std::to_string(mNumAllocs);
#define CPPCORE_NONE_COPYING(name)
This macro marks a class a not copyable.
size_t freeMem() const
Returns the free memory in bytes.
void reserve(size_t size)
bool release(T *ptr)
Will release the last item from the stack.
size_t reservedMem() const
Returns the allocated memory in bytes.
~TStackAllocator()
The class destructor.
TStackAllocator()=default
The default class constructor.
void reset()
Will reset the allocated memory, all used data will be marked as invalid.
void clear()
Will clear the whole memory, all used data will be marked as invalid.
size_t capacity() const
Returns the number of allocated instances on the stack.
void dumpAllocations(std::string &allocs)
Will dump a statistic overview into the given string.
T * alloc(size_t size)
Will allocate the number of items from the stack.