Cogs.Core
Public Member Functions | Private Member Functions | List of all members
Cogs::Collections::ConfigurablePagedPool< Context, Page, Item > Class Template Reference

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.
 
Itemallocate ()
 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.
 

Detailed Description

template<typename Context, typename Page, typename Item>
class Cogs::Collections::ConfigurablePagedPool< Context, Page, Item >

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.

Template Parameters
ContextProvides global context for all pages during allocation.
PageType of page to store. A new page is allocated on demand when the number of items in the pool exceed the current capacity.
ItemType of item stored in the pool.

Definition at line 91 of file ConfigurablePagedPool.h.

Constructor & Destructor Documentation

◆ ConfigurablePagedPool()

template<typename Context , typename Page , typename Item >
Cogs::Collections::ConfigurablePagedPool< Context, Page, Item >::ConfigurablePagedPool ( Context  context,
size_t  capacity,
size_t  pageSize 
)
inline

Constructs a pool with the given context, capacity and pageSize.

Parameters
contextAllocation context with parameters and data required during page construction.
capacityInitial capacity of the pool. Will be spread over a number of pages based on the given page size.
pageSizeNumber 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().

Member Function Documentation

◆ addPage()

template<typename Context , typename Page , typename Item >
void Cogs::Collections::ConfigurablePagedPool< Context, Page, Item >::addPage ( )
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().

◆ allocate()

template<typename Context , typename Page , typename Item >
Item * Cogs::Collections::ConfigurablePagedPool< Context, Page, Item >::allocate ( )
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.

Returns
Pointer to the allocated item.

Definition at line 143 of file ConfigurablePagedPool.h.

References Cogs::Collections::ConfigurablePagedPool< Context, Page, Item >::resize().

◆ deallocate()

template<typename Context , typename Page , typename Item >
void Cogs::Collections::ConfigurablePagedPool< Context, Page, Item >::deallocate ( Item item)
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.

Parameters
itemPointer to the item to deallocate.

Definition at line 161 of file ConfigurablePagedPool.h.

◆ initialize()

template<typename Context , typename Page , typename Item >
void Cogs::Collections::ConfigurablePagedPool< Context, Page, Item >::initialize ( Context  context,
size_t  capacity,
size_t  pageSize 
)
inline

Initialize the pool with the given parameters.

Parameters
contextAllocation context with parameters and data required during page construction.
capacityInitial capacity of the pool. Will be spread over a number of pages based on the given page size.
pageSizeNumber 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().

◆ resize()

template<typename Context , typename Page , typename Item >
void Cogs::Collections::ConfigurablePagedPool< Context, Page, Item >::resize ( size_t  capacity)
inline

The documentation for this class was generated from the following file: