15 template<
typename ElementType>
21 Pool(MemBlockType memType = MemBlockType::Bucket) :
Pool(1024, 1024, memType) {}
31 Pool(
ElementOffset capacity,
ElementOffset pageSize = 128, MemBlockType memType = MemBlockType::Bucket) :
Pool(capacity, pageSize, Memory::Allocator::defaultAllocator(), memType) {}
59 void resize(
size_t capacity) { base.resize(capacity); }
68 template<
typename... ARGS>
71 return new (base.allocate()) ElementType(std::forward<ARGS>(args)...);
84 element->~ElementType();
86 base.deallocate(element);
92 size_t size()
const {
return base.size(); }
128 return static_cast<ElementType *
>(base.getElement(handle));
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.
Pool used to store elements of ElementType.
Pool(ElementOffset capacity, ElementOffset pageSize=128, MemBlockType memType=MemBlockType::Bucket)
Create a pool with the given capacity and page sizes given in number of elements.
void resize(size_t capacity)
Resize the pool to the given capacity.
Pool(Pool &&) noexcept=default
Defaulted move constructor.
Pool(ElementOffset capacity, ElementOffset pageSize, Memory::Allocator *allocator, MemBlockType memType=MemBlockType::Bucket)
Create a pool with the given capacity and page sizes given in number of elements.
bool isAllocated(ElementHandle handle) const
Checks if the given handle is a valid handle to an allocated element.
bool isValid(ElementHandle handle) const
Checks if the given handle is a valid handle to an allocated or free element.
ElementType * operator[](ElementHandle handle)
Lookup an element using the handle given, using constant time.
ElementType * create(ARGS &&... args)
Allocate and initialize a new element from the pool passing any arguments to the constructor of the n...
ElementHandle getHandle(ElementType *element) const
Get a handle for the given element.
Pool(MemBlockType memType=MemBlockType::Bucket)
Create a pool with default capacity and page size.
size_t getPageSize() const
Get the page size in number of elements.
size_t getCapacity() const
Get the capacity of the pool, i.e the number of elements that may be allocated before any additional ...
size_t size() const
Get the size of the pool, i.e the number of created elements.
void destroy(ElementType *element)
Free and destroy the given element in the pool.