Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
Pool Class Referenceabstract

Pool of previously allocated, but currently unused, items. More...

#include <Buffer.hxx>

Inheritance diagram for Pool:
DataBufferPool DynamicPool FixedPool LimitedPool

Public Member Functions

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.
 
virtual size_t free_items ()=0
 Number of free items in the pool.
 
virtual size_t free_items (size_t size)=0
 Number of free items in the pool for a given allocation size.
 

Static Public Member Functions

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

 Pool ()
 Default Constructor.
 
virtual ~Pool ()
 default destructor.
 
virtual BufferBasealloc_untyped (size_t size, Executable *flow)=0
 Untyped buffer allocation method, used be descendants.
 
virtual void free (BufferBase *item)=0
 Release an item back to the free pool.
 

Protected Attributes

size_t totalSize
 keep track of total allocated size of memory
 

Private Member Functions

 DISALLOW_COPY_AND_ASSIGN (Pool)
 

Friends

class BufferBase
 Allow BufferBase to access this class.
 
class LimitedPool
 LimitedPool proxies to a base Pool.
 
class DataBufferPool
 DataBufferPool proxies to a base Pool.
 
template<class T >
class Buffer
 Allow Buffer to access this class.
 

Detailed Description

Pool of previously allocated, but currently unused, items.

Definition at line 277 of file Buffer.hxx.

Constructor & Destructor Documentation

◆ Pool()

Pool::Pool ( )
inlineprotected

Default Constructor.

Definition at line 353 of file Buffer.hxx.

◆ ~Pool()

virtual Pool::~Pool ( )
inlineprotectedvirtual

default destructor.

Definition at line 360 of file Buffer.hxx.

Member Function Documentation

◆ alloc() [1/2]

template<class BufferType >
void Pool::alloc ( Buffer< BufferType > **  result,
Executable flow = NULL 
)
inline

Get a free item out of the pool.

Parameters
resultpointer to a pointer to the result
flowif !NULL, then the alloc call is considered async and will behave as if alloc_async() was called.

Definition at line 292 of file Buffer.hxx.

◆ alloc() [2/2]

template<class BufferType >
void Pool::alloc ( BufferPtr< BufferType > *  result)
inline

Get a free item out of the pool.

This is a synchronous call.

Parameters
resultBuffer pointer that will hold the result

Definition at line 309 of file Buffer.hxx.

◆ alloc_async()

template<class BufferType >
void Pool::alloc_async ( Executable flow)
inline

Get a free item out of the pool.

Parameters
flowExecutable to notify upon allocation

Definition at line 319 of file Buffer.hxx.

◆ alloc_async_init()

template<class BufferType >
static void Pool::alloc_async_init ( BufferBase base,
Buffer< BufferType > **  result 
)
inlinestatic

Cast the result of an asynchronous allocation and perform a placement new on it.

Parameters
baseuntyped buffer
resultpointer to a pointer to the cast result

Definition at line 331 of file Buffer.hxx.

◆ alloc_untyped()

virtual BufferBase * Pool::alloc_untyped ( size_t  size,
Executable flow 
)
protectedpure virtual

Untyped buffer allocation method, used be descendants.

Parameters
sizeisthe number of bytes the buffer should have as payload.
flowis non-null, then asynchronous allocation is performed and the flow is called with the new buffer when it is available.
Returns
the new buffer or nullptr if out of RAM and async allocation was allowed.

Implemented in DynamicPool, FixedPool, DataBufferPool, and LimitedPool.

◆ free()

virtual void Pool::free ( BufferBase item)
protectedpure virtual

Release an item back to the free pool.

Parameters
itempointer to item to release

Implemented in DynamicPool, FixedPool, DataBufferPool, and LimitedPool.

◆ free_items() [1/2]

virtual size_t Pool::free_items ( )
pure virtual

Number of free items in the pool.

Returns
number of free items in the pool

Implemented in DynamicPool, FixedPool, DataBufferPool, and LimitedPool.

◆ free_items() [2/2]

virtual size_t Pool::free_items ( size_t  size)
pure virtual

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

Implemented in DynamicPool, FixedPool, DataBufferPool, and LimitedPool.

◆ total_size()

size_t Pool::total_size ( )
inline
Returns
the total memory held by this pool.

Definition at line 281 of file Buffer.hxx.

Friends And Related Symbol Documentation

◆ Buffer

template<class T >
friend class Buffer
friend

Allow Buffer to access this class.

Definition at line 388 of file Buffer.hxx.

◆ BufferBase

friend class BufferBase
friend

Allow BufferBase to access this class.

Definition at line 381 of file Buffer.hxx.

◆ DataBufferPool

friend class DataBufferPool
friend

DataBufferPool proxies to a base Pool.

Definition at line 385 of file Buffer.hxx.

◆ LimitedPool

friend class LimitedPool
friend

LimitedPool proxies to a base Pool.

Definition at line 383 of file Buffer.hxx.

Member Data Documentation

◆ totalSize

size_t Pool::totalSize
protected

keep track of total allocated size of memory

Definition at line 377 of file Buffer.hxx.


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