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

A specialization of a pool which can allocate new elements dynamically upon request. More...

#include <Buffer.hxx>

Inheritance diagram for DynamicPool:
Pool Atomic

Public Member Functions

 DynamicPool (Bucket sizes[])
 Constructor.
 
 ~DynamicPool ()
 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.
 

Protected Attributes

Bucketbuckets
 Free buffer queue.
 
- 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 * alloc_large (size_t size)
 Allocates a large memory block directly from the heap.
 
void free_large (void *block)
 Frees a large memory block allocated by alloc_large.
 
void free (BufferBase *item) override
 Releases an item back to the free pool.
 
 DynamicPool ()
 Default constructor.
 
 DISALLOW_COPY_AND_ASSIGN (DynamicPool)
 
- Private Member Functions inherited from Atomic
void lock ()
 
void unlock ()
 

Friends

class ForwardAllocator
 

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

A specialization of a pool which can allocate new elements dynamically upon request.

Definition at line 490 of file Buffer.hxx.

Constructor & Destructor Documentation

◆ DynamicPool()

DynamicPool::DynamicPool ( Bucket  sizes[])
inline

Constructor.

Parameters
sizesarray of bucket sizes for the pool

Definition at line 496 of file Buffer.hxx.

◆ ~DynamicPool()

DynamicPool::~DynamicPool ( )
inline

default destructor

Definition at line 503 of file Buffer.hxx.

Member Function Documentation

◆ alloc_large()

void * DynamicPool::alloc_large ( size_t  size)
private

Allocates a large memory block directly from the heap.

Parameters
sizeis the block size to allocate from the heap.
Returns
the allocated block.

Definition at line 154 of file Buffer.cxx.

◆ alloc_untyped()

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

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.
Returns
the allocated buffer base. The caller has to run the constructor on the returned object to initialize to a specific type.
Parameters
sizetells how much to allocate (in bytes)
flowif !NULL, then the alloc call is considered async and will behave as if alloc_async() was called.
Returns
the allocated buffer.

Implements Pool.

Definition at line 105 of file Buffer.cxx.

◆ free()

void DynamicPool::free ( BufferBase item)
overrideprivatevirtual

Releases an item back to the free pool.

Release an item back to the free pool.

Parameters
itempointer to item to release

Implements Pool.

Definition at line 165 of file Buffer.cxx.

◆ free_items() [1/2]

size_t DynamicPool::free_items ( )
overridevirtual

Number of free items in the pool.

Returns
number of free items in the pool

Implements Pool.

Definition at line 57 of file Buffer.cxx.

◆ free_items() [2/2]

size_t DynamicPool::free_items ( size_t  size)
overridevirtual

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 71 of file Buffer.cxx.

◆ free_large()

void DynamicPool::free_large ( void *  block)
private

Frees a large memory block allocated by alloc_large.

Parameters
blockis the memory block to free.

Definition at line 158 of file Buffer.cxx.

Friends And Related Symbol Documentation

◆ ForwardAllocator

friend class ForwardAllocator
friend

Definition at line 565 of file Buffer.hxx.

Member Data Documentation

◆ buckets

Bucket* DynamicPool::buckets
protected

Free buffer queue.

Definition at line 536 of file Buffer.hxx.


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