BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdlma::ConcurrentPool Class Reference

#include <bdlma_concurrentpool.h>

Public Member Functions

 ConcurrentPool (bsls::Types::size_type blockSize, bslma::Allocator *basicAllocator=0)
 
 ConcurrentPool (bsls::Types::size_type blockSize, bsls::BlockGrowth::Strategy growthStrategy, bslma::Allocator *basicAllocator=0)
 
 ConcurrentPool (bsls::Types::size_type blockSize, bsls::BlockGrowth::Strategy growthStrategy, int maxBlocksPerChunk, bslma::Allocator *basicAllocator=0)
 
 ~ConcurrentPool ()
 
void * allocate ()
 
void deallocate (void *address)
 
template<class TYPE >
void deleteObject (const TYPE *object)
 
template<class TYPE >
void deleteObjectRaw (const TYPE *object)
 
void release ()
 Relinquish all memory currently allocated via this pool object.
 
void reserveCapacity (int numBlocks)
 
bsls::Types::size_type blockSize () const
 
bslma::Allocatorallocator () const
 

Detailed Description

This class implements a memory pool that allocates and manages memory blocks of some uniform size specified at construction. This memory pool maintains an internal linked list of free memory blocks, and dispenses one block for each allocate method invocation. When a memory block is deallocated, it is returned to the free list for potential reuse.

This class guarantees thread safety while allocating or releasing memory.

See bdlma_concurrentpool

Constructor & Destructor Documentation

◆ ConcurrentPool() [1/3]

bdlma::ConcurrentPool::ConcurrentPool ( bsls::Types::size_type  blockSize,
bslma::Allocator basicAllocator = 0 
)
explicit

◆ ConcurrentPool() [2/3]

bdlma::ConcurrentPool::ConcurrentPool ( bsls::Types::size_type  blockSize,
bsls::BlockGrowth::Strategy  growthStrategy,
bslma::Allocator basicAllocator = 0 
)

◆ ConcurrentPool() [3/3]

bdlma::ConcurrentPool::ConcurrentPool ( bsls::Types::size_type  blockSize,
bsls::BlockGrowth::Strategy  growthStrategy,
int  maxBlocksPerChunk,
bslma::Allocator basicAllocator = 0 
)

Create a memory pool that returns blocks of contiguous memory of the specified blockSize (in bytes) for each allocate method invocation. Optionally specify a growthStrategy used to control the growth of internal memory chunks (from which memory blocks are dispensed). If growthStrategy is not specified, geometric growth is used. Optionally specify maxBlocksPerChunk as the maximum chunk size. If geometric growth is used, the chunk size grows starting at blockSize, doubling in size until the size is exactly blockSize * maxBlocksPerChunk. If constant growth is used, the chunk size is always maxBlocksPerChunk. If maxBlocksPerChunk is not specified, an implementation-defined value is used. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used. The behavior is undefined unless 1 <= blockSize and 1 <= maxBlocksPerChunk.

◆ ~ConcurrentPool()

bdlma::ConcurrentPool::~ConcurrentPool ( )

Destroy this pool, releasing all associated memory back to the underlying allocator.

Member Function Documentation

◆ allocate()

void * bdlma::ConcurrentPool::allocate ( )

Return the address of a contiguous block of memory having the fixed block size specified at construction.

◆ allocator()

bslma::Allocator * bdlma::ConcurrentPool::allocator ( ) const
inline

Return the allocator used by this object to allocate memory. Note that this allocator can not be used to deallocate memory allocated through this pool.

◆ blockSize()

bsls::Types::size_type bdlma::ConcurrentPool::blockSize ( ) const
inline

Return the size (in bytes) of the memory blocks allocated from this pool object. Note that all blocks dispensed by this pool have the same size.

◆ deallocate()

void bdlma::ConcurrentPool::deallocate ( void *  address)

Relinquish the memory block at the specified address back to this pool object for reuse. The behavior is undefined unless address is non-zero, was allocated by this pool, and has not already been deallocated.

◆ deleteObject()

template<class TYPE >
void bdlma::ConcurrentPool::deleteObject ( const TYPE *  object)
inline

Destroy the specified object based on its dynamic type and then use this pool to deallocate its memory footprint. This method has no effect if object is 0. The behavior is undefined unless object, when cast appropriately to void *, was allocated using this pool and has not already been deallocated. Note that dynamic_cast<void *>(object) is applied if TYPE is polymorphic, and static_cast<void *>(object) is applied otherwise.

◆ deleteObjectRaw()

template<class TYPE >
void bdlma::ConcurrentPool::deleteObjectRaw ( const TYPE *  object)
inline

Destroy the specified object and then use this pool to deallocate its memory footprint. This method has no effect if object is 0. The behavior is undefined unless object is not a secondary base class pointer (i.e., the address is (numerically) the same as when it was originally dispensed by this pool), was allocated using this pool, and has not already been deallocated.

◆ release()

void bdlma::ConcurrentPool::release ( )
inline

◆ reserveCapacity()

void bdlma::ConcurrentPool::reserveCapacity ( int  numBlocks)

Reserve memory from this pool to satisfy memory requests for at least the specified numBlocks before the pool replenishes. The behavior is undefined unless 0 <= numBlocks.


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