Quick Links:

bal | bbl | bdl | bsl

Classes | Public Member Functions

bdlma::ConcurrentPool Class Reference

#include <bdlma_concurrentpool.h>

List of all members.

Classes

struct  Link

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 ()
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 Component bdlma_concurrentpool


Constructor & Destructor Documentation

bdlma::ConcurrentPool::ConcurrentPool ( bsls::Types::size_type  blockSize,
bslma::Allocator basicAllocator = 0 
) [explicit]
bdlma::ConcurrentPool::ConcurrentPool ( bsls::Types::size_type  blockSize,
bsls::BlockGrowth::Strategy  growthStrategy,
bslma::Allocator basicAllocator = 0 
)
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.

bdlma::ConcurrentPool::~ConcurrentPool (  ) 

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


Member Function Documentation

void* bdlma::ConcurrentPool::allocate (  ) 

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

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.

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

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.

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

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.

void bdlma::ConcurrentPool::release (  ) 

Relinquish all memory currently allocated via this pool object.

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.

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

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.

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

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.


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