Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
FixedPool Class Reference

Pool of fixed number of items which can be allocated up on request. More...

#include <Buffer.hxx>

Inheritance diagram for FixedPool:
Pool Atomic

Public Member Functions

bool valid (QMember *item)
 Used in static pools to tell if this item is a member of the pool.
 
 FixedPool (size_t item_size, size_t items)
 Constructor for a fixed size pool.
 
 ~FixedPool ()
 default destructor
 
size_t free_items () override
 Number of free items in the pool.
 
size_t free_items (size_t size) override
 Number of free items in the pool for a given allocation size.
 
- Public Member Functions inherited from Pool
size_t total_size ()
 
template<class BufferType >
void alloc (Buffer< BufferType > **result, Executable *flow=NULL)
 Get a free item out of the pool.
 
template<class BufferType >
void alloc (BufferPtr< BufferType > *result)
 Get a free item out of the pool.
 
template<class BufferType >
void alloc_async (Executable *flow)
 Get a free item out of the pool.
 
- Public Member Functions inherited from Atomic
void lock ()
 
void unlock ()
 

Protected Attributes

Q queue
 Free buffer queue.
 
char * mempool
 First buffer in a pre-allocated array pool.
 
size_t itemSize
 item Size for fixed pools
 
size_t items
 total number of items in the queue
 
bool empty
 is the pool empty
 
- Protected Attributes inherited from Pool
size_t totalSize
 keep track of total allocated size of memory
 

Private Member Functions

BufferBasealloc_untyped (size_t size, Executable *flow) override
 Get a free item out of the pool.
 
void free (BufferBase *item) override
 Release an item back to the free pool.
 
 FixedPool ()
 Default Constructor.
 
 DISALLOW_COPY_AND_ASSIGN (FixedPool)
 

Additional Inherited Members

- Static Public Member Functions inherited from Pool
template<class BufferType >
static void alloc_async_init (BufferBase *base, Buffer< BufferType > **result)
 Cast the result of an asynchronous allocation and perform a placement new on it.
 
- Protected Member Functions inherited from Pool
 Pool ()
 Default Constructor.
 
virtual ~Pool ()
 default destructor.
 

Detailed Description

Pool of fixed number of items which can be allocated up on request.

Definition at line 572 of file Buffer.hxx.

Constructor & Destructor Documentation

◆ FixedPool()

FixedPool::FixedPool ( size_t  item_size,
size_t  items 
)
inline

Constructor for a fixed size pool.

Parameters
item_sizesize of each item in the pool (including the Buffer wrapper).
itemsnumber of items in the pool

Definition at line 594 of file Buffer.hxx.

◆ ~FixedPool()

FixedPool::~FixedPool ( )
inline

default destructor

Definition at line 612 of file Buffer.hxx.

Member Function Documentation

◆ alloc_untyped()

BufferBase * FixedPool::alloc_untyped ( size_t  size,
Executable flow 
)
overrideprivatevirtual

Get a free item out of the pool.

Parameters
sizethe number of bytes of the buffer payload that we need to allocate.
flowif !NULL, then the alloc call is considered async and will behave as if alloc_async() was called.
Returns
newly allocated buffer or nullptr if there was no buffer on the empty queue to allocate.
Parameters
sizehow many payload bytes should he allocated buffer have. Usually sizeof<T> for Buffer<T>.
flowif !NULL, then the alloc call is considered async and will behave as if alloc_async() was called.
Returns
the allocated buffer or NULL if there was no memory and we're doing asynchronous allocation.

Implements Pool.

Definition at line 197 of file Buffer.cxx.

◆ free()

void FixedPool::free ( BufferBase item)
overrideprivatevirtual

Release an item back to the free pool.

Parameters
itempointer to item to release

Implements Pool.

Definition at line 231 of file Buffer.cxx.

◆ free_items() [1/2]

size_t FixedPool::free_items ( )
inlineoverridevirtual

Number of free items in the pool.

Returns
number of free items in the pool

Implements Pool.

Definition at line 620 of file Buffer.hxx.

◆ free_items() [2/2]

size_t FixedPool::free_items ( size_t  size)
inlineoverridevirtual

Number of free items in the pool for a given allocation size.

Parameters
sizesize of interest
Returns
number of free items in the pool for a given allocation size

Implements Pool.

Definition at line 629 of file Buffer.hxx.

◆ valid()

bool FixedPool::valid ( QMember item)
inline

Used in static pools to tell if this item is a member of the pool.

Parameters
itemto test validity on
Returns
true if the item is in the pool, else return false;

Definition at line 579 of file Buffer.hxx.

Member Data Documentation

◆ empty

bool FixedPool::empty
protected

is the pool empty

Definition at line 648 of file Buffer.hxx.

◆ items

size_t FixedPool::items
protected

total number of items in the queue

Definition at line 645 of file Buffer.hxx.

◆ itemSize

size_t FixedPool::itemSize
protected

item Size for fixed pools

Definition at line 642 of file Buffer.hxx.

◆ mempool

char* FixedPool::mempool
protected

First buffer in a pre-allocated array pool.

Definition at line 639 of file Buffer.hxx.

◆ queue

Q FixedPool::queue
protected

Free buffer queue.

Definition at line 636 of file Buffer.hxx.


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