3#include "../Memory/MemoryBuffer.h"
5#include <OsoMemoryProfiler/CogsMemoryProfile.h>
32 PoolBase(
size_t elementSize,
size_t initialCapacity,
size_t pageSize,
Memory::Allocator * allocator = Memory::Allocator::defaultAllocator(), MemBlockType memType=MemBlockType::Bucket);
54 void resize(
size_t capacity);
69 void deallocate(
void * element);
74 size_t size()
const {
return numAllocated; }
110 const auto pageIndex = getPageIndex(handle);
111 const auto elementIndex = getElementOffset(handle);
112 return (pageIndex < pages.size()) && (elementIndex < pageSize);
132 void addPage(
size_t pageSize);
135 std::vector<Memory::MemoryBuffer> pages;
137 void * freeHead =
nullptr;
139 size_t numAllocated = 0;
140 size_t elementSize = 0;
145 MemBlockType memType = MemBlockType::Bucket;
Base allocator implementation.
uint16_t ElementOffset
Offset type used to index elements in resource pools.
uint32_t ElementHandle
Handle type for elements.
Contains all Cogs related functionality.
PoolBase(const PoolBase &)=delete
Disallow copying PoolBase instances.
size_t getCapacity() const
Get the capacity of the pool, in number of elements.
PoolBase(PoolBase &&)=default
Defaulted move constructor.
size_t getPageSize() const
Get the page size used by the pool, given in number of elements.
constexpr ElementOffset getElementOffset(ElementHandle handle) const
Gets the index inside a page of the element handle.
size_t size() const
Get the size of the pool, i.e the number of allocated elements.
constexpr uint32_t getPageIndex(ElementHandle handle) const
Gets the page index of the element handle.
PoolBase & operator=(const PoolBase &)=delete
Disallow copy-assigning PoolBase instances.
bool isValid(ElementHandle handle) const
Checks if the given handle is a valid handle to an allocated or free element.