Quick Links:

bal | bbl | bdl | bsl

Public Member Functions

bdlma::ConcurrentFixedPool Class Reference

#include <bdlma_concurrentfixedpool.h>

List of all members.

Public Member Functions

 ConcurrentFixedPool (int objectSize, int poolSize, bslma::Allocator *basicAllocator=0)
 ~ConcurrentFixedPool ()
void * allocate ()
void deallocate (void *address)
template<class TYPE >
void deleteObject (const TYPE *object)
template<class TYPE >
void deleteObjectRaw (const TYPE *object)
void release ()
int reserveCapacity (int numObjects)
void setBackoffLevel (int backoffLevel)
int backoffLevel () const
int indexFromAddress (void *address) const
int objectSize () const
void * addressFromIndex (int index) const
int poolSize () const
bslma::Allocatorallocator () const

Detailed Description

This class implements a memory pool that allocates and manages up to a fixed number of memory blocks of some uniform size, with both the limit on the number of blocks and the block size specified at construction.

This class guarantees thread safety when allocating or releasing memory (but see the documentation for the release method).

See Component bdlma_concurrentfixedpool


Constructor & Destructor Documentation

bdlma::ConcurrentFixedPool::ConcurrentFixedPool ( int  objectSize,
int  poolSize,
bslma::Allocator basicAllocator = 0 
)

Create a memory pool that returns memory of the specified objectSize for each invocation of the allocate method. Configure this pool to support allocation of up to the specified poolSize number of memory blocks. The largest supported poolSize is 33554431. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used. The behavior is undefined unless 0 < objectSize, 0 < poolSize, and 0x1FFFFFF >= poolSize.

bdlma::ConcurrentFixedPool::~ConcurrentFixedPool (  ) 

Destroy this object and release all associated memory.


Member Function Documentation

void* bdlma::ConcurrentFixedPool::allocate (  ) 

Allocate a memory block of the objectSize specified at construction. Return the address of that block or 0 if the pool is exhausted (i.e., poolSize() memory blocks have already been allocated from this pool).

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

Deallocate the memory block at the specified address back to this pool for reuse.

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

Destroy the specified object based on its dynamic type and then use this allocator to deallocate its memory footprint. Do nothing if object is 0. The behavior is undefined unless object, when cast appropriately to void *, was allocated using this allocator 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::ConcurrentFixedPool::deleteObjectRaw ( const TYPE *  object  ) 

Destroy the specified object based on its static type and then use this allocator to deallocate its memory footprint. Do nothing if object is 0. The behavior is undefined if object is a base-class pointer to a derived type, was not allocated using this allocator, or has already been deallocated.

void bdlma::ConcurrentFixedPool::release (  ) 

Release all memory currently allocated through this object. Note that this method should only be invoked when it is known that no blocks currently allocated through this pool will be used; therefore, it is not safe to use this method if any other thread may be concurrently allocating memory from this pool. Also note that release() is intended to free all memory without regard to the contents of that memory. Specifically, release() can not call object destructors for any allocated objects, since it has no knowledge of their type. If object destruction is required, use ConcurrentFixedPool::deleteObject().

int bdlma::ConcurrentFixedPool::reserveCapacity ( int  numObjects  ) 

Reserve memory from this pool to satisfy memory requests for at least the specified numObjects before the pool replenishes. The behavior is undefined unless 0 <= numObjects. Return 0 on success and the number of objects that could not be reserved otherwise. Note that this method fails if the number of memory blocks already allocated plus numObjects exceeds poolSize().

void bdlma::ConcurrentFixedPool::setBackoffLevel ( int  backoffLevel  ) 

Configure this pool with the specified non-negative backoffLevel that controls the amount of spinning that occurs when calls to this pool encounter contention. Setting backoffLevel to 0 disables spinning. Greater values of backoffLevel correspond to greater amounts of spinning. The behavior is undefined unless 0 <= backoffLevel. Note that both contention detection and spinning strategy are implementation defined.

int bdlma::ConcurrentFixedPool::backoffLevel (  )  const

Return the non-negative backoffLevel that controls the amount of spinning that occurs when calls to this pool encounter contention.

int bdlma::ConcurrentFixedPool::indexFromAddress ( void *  address  )  const

Return an index in the range from 0 to the maximum size of this pool that uniquely identifies the memory block at the specified address. The behavior is undefined unless address corresponds to a memory block allocated from this pool.

int bdlma::ConcurrentFixedPool::objectSize (  )  const

Return the size of the memory blocks allocated from this object. Note that all blocks have the same size.

void* bdlma::ConcurrentFixedPool::addressFromIndex ( int  index  )  const

Return the address of the memory block identified by the specified index. The behavior is undefined unless the index has been obtained through indexFromAddress.

int bdlma::ConcurrentFixedPool::poolSize (  )  const

Return the maximum size of this pool.

bslma::Allocator* bdlma::ConcurrentFixedPool::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: