Cogs.Core
|
Provides a configurable pool implementation usable as base implementation for several pool-like storage scenarios. More...
#include <ConfigurablePagedPool.h>
Public Member Functions | |
ConfigurablePagedPool ()=default | |
Constructs a default, empty pool. | |
ConfigurablePagedPool (Context context, size_t capacity, size_t pageSize) | |
Constructs a pool with the given context, capacity and pageSize. | |
void | initialize (Context context, size_t capacity, size_t pageSize) |
Initialize the pool with the given parameters. | |
Item * | allocate () |
Allocates storage for a new item and returns a pointer to the item. | |
void | deallocate (Item *item) |
Deallocate the given item. | |
void | resize (size_t capacity) |
Resize the pool to the given capacity. | |
Private Member Functions | |
void | addPage () |
Adds a new page to the pool, linking its reserved elements with any current free elements. | |
Provides a configurable pool implementation usable as base implementation for several pool-like storage scenarios.
The pool tracks free item instances also after deallocating used items, and so provides reuse of the most recently used instances.
Context | Provides global context for all pages during allocation. |
Page | Type of page to store. A new page is allocated on demand when the number of items in the pool exceed the current capacity. |
Item | Type of item stored in the pool. |
Definition at line 91 of file ConfigurablePagedPool.h.
|
inline |
Constructs a pool with the given context, capacity and pageSize.
context | Allocation context with parameters and data required during page construction. |
capacity | Initial capacity of the pool. Will be spread over a number of pages based on the given page size. |
pageSize | Number of elements to store per page. This limits the granularity of the pool by setting the number of elements to grow the capacity by when needed. |
Definition at line 106 of file ConfigurablePagedPool.h.
References Cogs::Collections::ConfigurablePagedPool< Context, Page, Item >::resize().
|
inlineprivate |
Adds a new page to the pool, linking its reserved elements with any current free elements.
Definition at line 181 of file ConfigurablePagedPool.h.
References Cogs::Collections::ItemHeader::next.
Referenced by Cogs::Collections::ConfigurablePagedPool< Context, Page, Item >::resize().
|
inline |
Allocates storage for a new item and returns a pointer to the item.
If the current capacity of the pool is exceeded (no reusable instances are present), a new page of items will be automatically added. Corresponding to manually calling resize(capacity + pageSize) on the pool instance.
NOTE: No constructors are performed for the returned Item instance, it is the users responsibility to either rely on the page having initialized the contents, or to execute constructors/initialization routines manually.
Definition at line 143 of file ConfigurablePagedPool.h.
References Cogs::Collections::ConfigurablePagedPool< Context, Page, Item >::resize().
|
inline |
Deallocate the given item.
NOTE: No destructors are run on the item. It is the callers responsibility to ensure item resources are properly cleaned up after use.
item | Pointer to the item to deallocate. |
Definition at line 161 of file ConfigurablePagedPool.h.
|
inline |
Initialize the pool with the given parameters.
context | Allocation context with parameters and data required during page construction. |
capacity | Initial capacity of the pool. Will be spread over a number of pages based on the given page size. |
pageSize | Number of elements to store per page. This limits the granularity of the pool by setting the number of elements to grow the capacity by when needed. |
Definition at line 122 of file ConfigurablePagedPool.h.
References Cogs::Collections::ConfigurablePagedPool< Context, Page, Item >::resize().
|
inline |
Resize the pool to the given capacity.
capacity | Desired capacity in number of elements. |
Definition at line 172 of file ConfigurablePagedPool.h.
References Cogs::Collections::ConfigurablePagedPool< Context, Page, Item >::addPage().
Referenced by Cogs::Collections::ConfigurablePagedPool< Context, Page, Item >::allocate(), Cogs::Collections::ConfigurablePagedPool< Context, Page, Item >::ConfigurablePagedPool(), and Cogs::Collections::ConfigurablePagedPool< Context, Page, Item >::initialize().