[#BloombergLP-bdlma-ConcurrentFixedPool] = xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bdlma.adoc[bdlma]::ConcurrentFixedPool :relfileprefix: ../../ :mrdocs: 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. == Synopsis Declared in `<bdlma_concurrentfixedpool.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- class ConcurrentFixedPool; ---- == Description This class guarantees thread safety when allocating or releasing memory (but see the documentation for the `release` method). == Member Functions [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bdlma/ConcurrentFixedPool/2constructor.adoc[`ConcurrentFixedPool`] [.small]#[constructor]# | 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`. | xref:BloombergLP/bdlma/ConcurrentFixedPool/2destructor.adoc[`~ConcurrentFixedPool`] [.small]#[destructor]# | Destroy this object and release all associated memory. | xref:BloombergLP/bdlma/ConcurrentFixedPool/addressFromIndex.adoc[`addressFromIndex`] | Return the address of the memory block identified by the specified `index`. The behavior is undefined unless the index has been obtained through `indexFromAddress`. | xref:BloombergLP/bdlma/ConcurrentFixedPool/allocate.adoc[`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). | xref:BloombergLP/bdlma/ConcurrentFixedPool/allocator.adoc[`allocator`] | 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. | xref:BloombergLP/bdlma/ConcurrentFixedPool/backoffLevel.adoc[`backoffLevel`] | Return the non‐negative `backoffLevel` that controls the amount of spinning that occurs when calls to this pool encounter contention. | xref:BloombergLP/bdlma/ConcurrentFixedPool/deallocate.adoc[`deallocate`] | Deallocate the memory block at the specified `address` back to this pool for reuse. | xref:BloombergLP/bdlma/ConcurrentFixedPool/deleteObject.adoc[`deleteObject`] | 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. | xref:BloombergLP/bdlma/ConcurrentFixedPool/deleteObjectRaw.adoc[`deleteObjectRaw`] | 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. | xref:BloombergLP/bdlma/ConcurrentFixedPool/indexFromAddress.adoc[`indexFromAddress`] | 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. | xref:BloombergLP/bdlma/ConcurrentFixedPool/objectSize.adoc[`objectSize`] | Return the size of the memory blocks allocated from this object. Note that all blocks have the same size. | xref:BloombergLP/bdlma/ConcurrentFixedPool/poolSize.adoc[`poolSize`] | Return the maximum size of this pool. | xref:BloombergLP/bdlma/ConcurrentFixedPool/release.adoc[`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()`. | xref:BloombergLP/bdlma/ConcurrentFixedPool/reserveCapacity.adoc[`reserveCapacity`] | 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()`. | xref:BloombergLP/bdlma/ConcurrentFixedPool/setBackoffLevel.adoc[`setBackoffLevel`] | 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. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#