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

#include <bdlma_pool.h>

Public Member Functions

 Pool (bsls::Types::size_type blockSize, bslma::Allocator *basicAllocator=0)
 
 Pool (bsls::Types::size_type blockSize, bsls::BlockGrowth::Strategy growthStrategy, bslma::Allocator *basicAllocator=0)
 
 Pool (bsls::Types::size_type blockSize, bsls::BlockGrowth::Strategy growthStrategy, int maxBlocksPerChunk, bslma::Allocator *basicAllocator=0)
 
 ~Pool ()
 
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.

See bdlma_pool

Constructor & Destructor Documentation

◆ Pool() [1/3]

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

◆ Pool() [2/3]

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

◆ Pool() [3/3]

bdlma::Pool::Pool ( 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 growthStrategy is specified. 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 blockSize * 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.

◆ ~Pool()

bdlma::Pool::~Pool ( )

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

Member Function Documentation

◆ allocate()

void * bdlma::Pool::allocate ( )
inline

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

◆ allocator()

bslma::Allocator * bdlma::Pool::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::Pool::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::Pool::deallocate ( void *  address)
inline

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::Pool::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::Pool::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::Pool::release ( )
inline

◆ reserveCapacity()

void bdlma::Pool::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: