94 void resize(
size_t growSize);
104 size_t mPoolsize{0u};
106 size_t mCurrentIdx{0u};
107 Pool *mNext{
nullptr};
111 Pool(
size_t numItems, Pool *prev) :
114 mPool =
new T[mPoolsize];
124 Pool *getFreePool() {
125 Pool *current = mFreeList;
126 if (
nullptr != mFreeList) {
127 mFreeList = mFreeList->mNext;
132 Pool *mFirst{
nullptr};
133 Pool *mCurrent{
nullptr};
134 Pool *mFreeList{
nullptr};
135 size_t mCapacity{0L};
140 mFirst =
new Pool(numItems,
nullptr);
141 mCapacity += numItems;
152 if (
nullptr == mCurrent) {
156 if (mCurrent->mCurrentIdx == mCurrent->mPoolsize) {
157 resize(mCurrent->mPoolsize);
160 T *ptr = &mCurrent->mPool[mCurrent->mCurrentIdx];
161 mCurrent->mCurrentIdx++;
168 if (
nullptr == mCurrent) {
172 Pool *current = mFirst;
173 while (
nullptr != current) {
174 current->mCurrentIdx = 0;
175 current = current->mNext;
177 mFreeList = mFirst->mNext;
185 mFirst =
new Pool(size,
nullptr);
188 mCurrent->mPool =
new T[size];
189 mCurrent->mPoolsize = size;
196 if (
nullptr == mCurrent) {
201 while (
nullptr != next) {
202 Pool *current = next;
203 next = current->mNext;
217 return mCapacity *
sizeof(T);
222 if (
nullptr == mCurrent) {
226 return (mCurrent->mPoolsize - mCurrent->mCurrentIdx);
232 allocs +=
"Number allocations = ";
233 allocs += std::to_string(mCurrent->mCurrentIdx);
239 if (
nullptr != mCurrent) {
240 if (growSize < mCurrent->mPoolsize) {
245 if (
nullptr == mFirst) {
246 mFirst =
new Pool(growSize,
nullptr);
248 mCapacity += mCurrent->mPoolsize;
250 Pool *pool = getFreePool();
251 if (
nullptr == pool) {
252 pool =
new Pool(growSize,
nullptr);
253 mCapacity += growSize;
255 mCurrent->mNext = pool;
256 mCurrent = mCurrent->mNext;
#define CPPCORE_NONE_COPYING(name)
This macro marks a class a not copyable.
size_t capacity() const
Returns the capacity of items in the pool allocator.
void reset()
Will reset the allocator.
TPoolAllocator()=default
The default class constructor.
T * alloc()
WIll alloc one item from the pool.
void reserve(size_t size)
Will reserve the pool.
void release()
Will release all allocated items.
void dumpAllocations(std::string &allocs)
Will dump a statistic overview into the given string.
void resize(size_t growSize)
Will perform a resize for the pool.
void clear()
Will clear the pool, memory will be deallocated.
size_t freeMem() const
Will return the free memory in the pool in bytes.
size_t reservedMem() const
WIll return the reserved memory in bytes.
~TPoolAllocator()
The class destructor.