[#BloombergLP-bdlcc-ObjectPool]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bdlcc.adoc[bdlcc]::ObjectPool
:relfileprefix: ../../
:mrdocs:

This class provides a thread&hyphen;safe pool of reusable objects&period; It also implements the `bdlma&colon;&colon;Factory` protocol&colon; &quot;creating&quot; objects gets them from the pool and &quot;deleting&quot; objects returns them to the pool&period;

== Synopsis

Declared in `&lt;bdlcc&lowbar;objectpool&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    class TYPE,
    class CREATOR = xref:BloombergLP/bdlcc/ObjectPoolFunctors/DefaultCreator.adoc[ObjectPoolFunctors::DefaultCreator],
    class RESETTER = xref:BloombergLP/bdlcc/ObjectPoolFunctors/Nil.adoc[ObjectPoolFunctors::Nil&lt;TYPE&gt;]&gt;
class ObjectPool
    : public xref:BloombergLP/bdlma/Factory.adoc[bdlma::Factory&lt;TYPE&gt;]
----

== Base Classes

[cols="1,4"]
|===
| Name| Description
| `xref:BloombergLP/bdlma/Factory.adoc[bdlma::Factory&lt;TYPE&gt;]`
| This `class` provides a protocol (or pure interface) for a thread&hyphen;safe object creator and deleter&period; It extends the `Deleter` protocol with the addition of a `createObject` method&period;
|===

== Type Aliases

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bdlcc/ObjectPool/CreatorType.adoc[`CreatorType`] 
| Type of the creator functor used by this pool&period;
| xref:BloombergLP/bdlcc/ObjectPool/ResetterType.adoc[`ResetterType`] 
| Type of the resetter functor used by this pool&period;
|===


== Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bdlcc/ObjectPool/2constructor-04.adoc[`ObjectPool`]         [.small]#[constructor]#
| Constructors
| xref:BloombergLP/bdlcc/ObjectPool/2destructor.adoc[`&#126;ObjectPool`] [.small]#[destructor]# [.small]#[virtual]#
| Destroy this object pool&period; All objects created by this pool are destroyed (even if some of them are still in use) and memory is reclaimed&period;
| xref:BloombergLP/bdlcc/ObjectPool/createObject.adoc[`createObject`]  [.small]#[virtual]#
| This concrete implementation of `bdlma&colon;&colon;Factory&colon;&colon;createObject` invokes `getObject`&period; This should not be invoked directly&period;
| xref:BloombergLP/bdlcc/ObjectPool/deleteObject-03.adoc[`deleteObject`] 
| `deleteObject` overloads
| xref:BloombergLP/bdlcc/ObjectPool/getObject.adoc[`getObject`] 
| Return an address of modifiable object from this object pool&period; If this pool is empty, it is replenished according to the strategy specified at the pool construction (or an implementation&hyphen;defined strategy if none was provided)&period;
| xref:BloombergLP/bdlcc/ObjectPool/increaseCapacity.adoc[`increaseCapacity`] 
| Create the specified `numObjects` objects and add them to this object pool&period; The behavior is undefined unless `0 &lt;&equals; numObjects`&period;
| xref:BloombergLP/bdlcc/ObjectPool/numAvailableObjects.adoc[`numAvailableObjects`] 
| Return a _snapshot_ of the number of objects available in this pool&period;
| xref:BloombergLP/bdlcc/ObjectPool/numObjects.adoc[`numObjects`] 
| Return the (instantaneous) number of objects managed by this pool&period; This includes both the objects available in the pool and the objects that were allocated from the pool and not yet released&period;
| xref:BloombergLP/bdlcc/ObjectPool/releaseObject.adoc[`releaseObject`] 
| Return the specified `object` back to this object pool&period; Invoke the RESETTER specified at construction, or the default RESETTER if none was provided, before making the object available for reuse&period; Note that if RESETTER is the default type (`ObjectPoolFunctors&colon;&colon;Nil`), then this method should be invoked to return only _valid_ objects because the pool uses the released objects to satisfy further `getObject` requests&period; The behavior is undefined unless the `object` was obtained from this object pool&apos;s `getObject` method and is not already in a released state&period;
| xref:BloombergLP/bdlcc/ObjectPool/reserveCapacity.adoc[`reserveCapacity`] 
| Create enough objects to satisfy requests for at least the specified `numObjects` objects before the next replenishment&period; The behavior is undefined unless `0 &lt;&equals; numObjects`&period; Note that this method is different from `increaseCapacity` in that the number of created objects may be less than `numObjects`&period;
| xref:BloombergLP/bdlcc/ObjectPool/2conversion.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration&lt;ObjectPool, UsesBslmaAllocator&gt;`] 
| Declare that this type uses a `bslma` allocator&period;
|===


== Friends

[cols="1,4"]
|===
| Name| Description
| `BloombergLP::bdlcc::ObjectPool::AutoCleanup`
| 
|===


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