Cogs.Foundation
|
Pool used to store elements of ElementType. More...
#include <Pool.h>
Public Member Functions | |
Pool (MemBlockType memType=MemBlockType::Bucket) | |
Create a pool with default capacity and page size. | |
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. | |
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. | |
Pool (Pool &&) noexcept=default | |
Defaulted move constructor. | |
Pool & | operator= (Pool &&) noexcept=default |
Defaulted move assignment operator. | |
Pool (const Pool &)=delete | |
Disallow copying Pool instances. | |
Pool & | operator= (const Pool &)=delete |
Disallow copy-assigning pool instances. | |
void | resize (size_t capacity) |
Resize the pool to the given capacity. | |
template<typename... ARGS> | |
ElementType * | create (ARGS &&... args) |
Allocate and initialize a new element from the pool passing any arguments to the constructor of the new item as necessary. | |
void | destroy (ElementType *element) |
Free and destroy the given element in the pool. | |
size_t | size () const |
Get the size of the pool, i.e the number of created elements. | |
size_t | getCapacity () const |
Get the capacity of the pool, i.e the number of elements that may be allocated before any additional pages must be created. | |
size_t | getPageSize () const |
Get the page size in number of elements. | |
ElementHandle | getHandle (ElementType *element) const |
Get a handle for the given element. | |
ElementType * | operator[] (ElementHandle handle) |
Lookup an element using the handle given, using constant time. | |
bool | isValid (ElementHandle handle) const |
Checks if the given handle is a valid handle to an allocated or free element. | |
bool | isAllocated (ElementHandle handle) const |
Checks if the given handle is a valid handle to an allocated element. | |
Pool used to store elements of ElementType.
ElementType | Type of elements to store in the pool. The size requirements for storage are at least the size of a pointer. |
|
inline |
Create a pool with default capacity and page size.
|
inline |
Create a pool with the given capacity and page sizes given in number of elements.
capacity | Total number of elements to allocate storage for, divided between capacity / pageSize number of pages. |
pageSize | Number of elements to store per page. Defaults to 128. Allocations will occur whenever the pool needs to grow into additional pages. |
|
inline |
Create a pool with the given capacity and page sizes given in number of elements.
capacity | Total number of elements to allocate storage for, divided between capacity / pageSize number of pages. |
pageSize | Number of elements to store per page. Defaults to 128. Allocations will occur whenever the pool needs to grow into additional pages. |
allocator | Pointer to an allocator to use when reserving page memory. |
|
defaultnoexcept |
Defaulted move constructor.
|
delete |
Disallow copying Pool instances.
|
inline |
Allocate and initialize a new element from the pool passing any arguments to the constructor of the new item as necessary.
The pool will grow as needed if no free elements are available to use or reuse.
|
inline |
Free and destroy the given element in the pool.
The element is returned to the list of free elements maintained by the pool and can be reused the next time an allocation is requested.
element | Pointer to the element to deallocate. |
|
inline |
Get the capacity of the pool, i.e the number of elements that may be allocated before any additional pages must be created.
|
inline |
Get a handle for the given element.
element | Pointer to a previously allocated element in the pool. |
|
inline |
Get the page size in number of elements.
Total page size in bytes will be numElements * sizeof(ElementType)
|
inline |
Checks if the given handle is a valid handle to an allocated element.
NOTE: Has to traverse free list to check. Can be time-consuming.
|
inline |
Checks if the given handle is a valid handle to an allocated or free element.
|
delete |
Disallow copy-assigning pool instances.
|
defaultnoexcept |
Defaulted move assignment operator.
|
inline |
Lookup an element using the handle given, using constant time.
Uses a handle previously fetched with getHandle() to look up and return a raw pointer to the element.
handle | Handle fetched with getHandle() used to look up the element. |
|
inline |
Resize the pool to the given capacity.
|
inline |
Get the size of the pool, i.e the number of created elements.