31 #include "Utilities/STL/MxVector.h" 32 #include "Utilities/Memory/PoolAllocator.h" 41 template<
typename T,
template<
typename>
typename Container = MxVector>
60 size_t GetBase()
const 76 : index(index), poolRef(ref)
132 return &poolRef[index];
141 return &poolRef[index];
150 return poolRef[index];
159 return poolRef[index];
168 return (index == it.index) && (&poolRef == &it.poolRef);
177 return !(*
this == it);
187 Container<uint8_t> memoryStorage;
195 size_t allocated = 0;
197 Block* GetBlockByIndex(
size_t index)
199 size_t byteIndex = index *
sizeof(Block);
200 MX_ASSERT(byteIndex < memoryStorage.size());
201 return (Block*)(memoryStorage.data() + byteIndex);
204 const Block* GetBlockByIndex(
size_t index)
const 206 size_t byteIndex = index *
sizeof(Block);
207 MX_ASSERT(byteIndex < memoryStorage.size());
208 return (Block*)(memoryStorage.data() + byteIndex);
231 if (count <= this->
Capacity())
return;
233 Container<uint8_t> newMemory(count *
sizeof(Block));
234 allocator.
Transfer(newMemory.data(), newMemory.size());
235 memoryStorage = std::move(newMemory);
244 return this->allocated;
253 return memoryStorage.size() /
sizeof(Block);
262 return GetBlockByIndex(index)->data;
271 return GetBlockByIndex(index)->data;
280 memoryStorage.clear();
290 return !GetBlockByIndex(index)->IsFree();
301 T& ptr = GetBlockByIndex(index)->data;
302 allocator.
Free(&ptr);
317 template<
typename... Args>
320 if (this->allocated == this->
Capacity())
322 size_t newSize = (this->allocated + 1) * 3 / 2;
326 T* obj = allocator.
Alloc(std::forward<Args>(args)...);
339 const uint8_t* ptr = (uint8_t*)&obj - offsetof(Block, data);
340 MX_ASSERT(memoryStorage.data() <= ptr && ptr < memoryStorage.data() + memoryStorage.size());
341 return (Block*)ptr - (Block*)memoryStorage.data();
const PoolIterator begin() const
Definition: VectorPool.h:357
void Deallocate(size_t index)
Definition: VectorPool.h:297
Definition: VectorPool.h:49
bool operator!=(const PoolIterator &it) const
Definition: VectorPool.h:175
void Transfer(DataPointer newData, size_t newBytes)
Definition: PoolAllocator.h:114
void Clear()
Definition: VectorPool.h:277
PoolIterator(size_t index, VectorPool< T, Container > &ref)
Definition: VectorPool.h:75
~PoolAllocator()
Definition: PoolAllocator.h:154
bool IsAllocated(size_t index)
Definition: VectorPool.h:288
T * operator->()
Definition: VectorPool.h:130
const PoolIterator end() const
Definition: VectorPool.h:375
size_t Allocated() const
Definition: VectorPool.h:242
void Resize(size_t count)
Definition: VectorPool.h:229
Definition: PoolAllocator.h:25
bool operator==(const PoolIterator &it) const
Definition: VectorPool.h:166
PoolIterator begin()
Definition: VectorPool.h:348
Definition: VectorPool.h:42
PoolIterator operator--(int)
Definition: VectorPool.h:109
T & operator*()
Definition: VectorPool.h:148
Definition: PoolAllocator.h:19
size_t Allocate(Args &&... args)
Definition: VectorPool.h:318
PoolIterator operator--()
Definition: VectorPool.h:120
size_t IndexOf(const T &obj)
Definition: VectorPool.h:337
T * Alloc(Args &&... args)
Definition: PoolAllocator.h:188
VectorPool(size_t count)
Definition: VectorPool.h:220
PoolIterator operator++()
Definition: VectorPool.h:99
size_t Capacity() const
Definition: VectorPool.h:251
T & operator[](size_t index)
Definition: VectorPool.h:260
Definition: Application.cpp:49
void Free(T *object)
Definition: PoolAllocator.h:202
PoolIterator end()
Definition: VectorPool.h:366
PoolIterator operator++(int)
Definition: VectorPool.h:88