[#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&period;

== Synopsis

Declared in `&lt;bdlma&lowbar;concurrentfixedpool&period;h&gt;`

[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)&period;

== 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&period; Configure this pool to support allocation of up to the specified `poolSize` number of memory blocks&period; The largest supported `poolSize` is 33554431&period; Optionally specify a `basicAllocator` used to supply memory&period; If `basicAllocator` is 0, the currently installed default allocator is used&period; The behavior is undefined unless `0 &lt; objectSize`, `0 &lt; poolSize`, and `0x1FFFFFF &gt;&equals; poolSize`&period;
| xref:BloombergLP/bdlma/ConcurrentFixedPool/2destructor.adoc[`&#126;ConcurrentFixedPool`] [.small]#[destructor]#
| Destroy this object and release all associated memory&period;
| xref:BloombergLP/bdlma/ConcurrentFixedPool/addressFromIndex.adoc[`addressFromIndex`] 
| Return the address of the memory block identified by the specified `index`&period; The behavior is undefined unless the index has been obtained through `indexFromAddress`&period;
| xref:BloombergLP/bdlma/ConcurrentFixedPool/allocate.adoc[`allocate`] 
| Allocate a memory block of the `objectSize` specified at construction&period; Return the address of that block or 0 if the pool is exhausted (i&period;e&period;, `poolSize()` memory blocks have already been allocated from this pool)&period;
| xref:BloombergLP/bdlma/ConcurrentFixedPool/allocator.adoc[`allocator`] 
| Return the allocator used by this object to allocate memory&period; Note that this allocator can not be used to deallocate memory allocated through this pool&period;
| xref:BloombergLP/bdlma/ConcurrentFixedPool/backoffLevel.adoc[`backoffLevel`] 
| Return the non&hyphen;negative `backoffLevel` that controls the amount of spinning that occurs when calls to this pool encounter contention&period;
| xref:BloombergLP/bdlma/ConcurrentFixedPool/deallocate.adoc[`deallocate`] 
| Deallocate the memory block at the specified `address` back to this pool for reuse&period;
| 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&period; Do nothing if `object` is 0&period; The behavior is undefined unless `object`, when cast appropriately to `void &ast;`, was allocated using this allocator and has not already been deallocated&period; Note that `dynamic&lowbar;cast&lt;void &ast;&gt;(object)` is applied if `TYPE` is polymorphic, and `static&lowbar;cast&lt;void &ast;&gt;(object)` is applied otherwise&period;
| 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&period; Do nothing if `object` is 0&period; The behavior is undefined if `object` is a base&hyphen;class pointer to a derived type, was not allocated using this allocator, or has already been deallocated&period;
| 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`&period; The behavior is undefined unless `address` corresponds to a memory block allocated from this pool&period;
| xref:BloombergLP/bdlma/ConcurrentFixedPool/objectSize.adoc[`objectSize`] 
| Return the size of the memory blocks allocated from this object&period; Note that all blocks have the same size&period;
| xref:BloombergLP/bdlma/ConcurrentFixedPool/poolSize.adoc[`poolSize`] 
| Return the maximum size of this pool&period;
| xref:BloombergLP/bdlma/ConcurrentFixedPool/release.adoc[`release`] 
| Release all memory currently allocated through this object&period; Note that this method should only be invoked when it is known that no blocks currently allocated through this pool will be used&semi; therefore, it is not safe to use this method if any other thread may be concurrently allocating memory from this pool&period; Also note that `release()` is intended to free all memory without regard to the contents of that memory&period; Specifically, `release()` can _not_ call object destructors for any allocated objects, since it has no knowledge of their type&period; If object destruction is required, use `ConcurrentFixedPool&colon;&colon;deleteObject()`&period;
| 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&period; The behavior is undefined unless `0 &lt;&equals; numObjects`&period; Return 0 on success and the number of objects that could not be reserved otherwise&period; Note that this method fails if the number of memory blocks already allocated plus `numObjects` exceeds `poolSize()`&period;
| xref:BloombergLP/bdlma/ConcurrentFixedPool/setBackoffLevel.adoc[`setBackoffLevel`] 
| Configure this pool with the specified non&hyphen;negative `backoffLevel` that controls the amount of spinning that occurs when calls to this pool encounter contention&period; Setting `backoffLevel` to 0 disables spinning&period; Greater values of `backoffLevel` correspond to greater amounts of spinning&period; The behavior is undefined unless `0 &lt;&equals; backoffLevel`&period; Note that both contention detection and spinning strategy are implementation defined&period;
|===



[.small]#Created with https://www.mrdocs.com[MrDocs]#
