[#BloombergLP-bdlcc-ObjectPool] = xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bdlcc.adoc[bdlcc]::ObjectPool :relfileprefix: ../../ :mrdocs: This class provides a thread‐safe pool of reusable objects. It also implements the `bdlma::Factory` protocol: "creating" objects gets them from the pool and "deleting" objects returns them to the pool. == Synopsis Declared in `<bdlcc_objectpool.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template< class TYPE, class CREATOR = xref:BloombergLP/bdlcc/ObjectPoolFunctors/DefaultCreator.adoc[ObjectPoolFunctors::DefaultCreator], class RESETTER = xref:BloombergLP/bdlcc/ObjectPoolFunctors/Nil.adoc[ObjectPoolFunctors::Nil<TYPE>]> class ObjectPool : public xref:BloombergLP/bdlma/Factory.adoc[bdlma::Factory<TYPE>] ---- == Base Classes [cols="1,4"] |=== | Name| Description | `xref:BloombergLP/bdlma/Factory.adoc[bdlma::Factory<TYPE>]` | This `class` provides a protocol (or pure interface) for a thread‐safe object creator and deleter. It extends the `Deleter` protocol with the addition of a `createObject` method. |=== == Type Aliases [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bdlcc/ObjectPool/CreatorType.adoc[`CreatorType`] | Type of the creator functor used by this pool. | xref:BloombergLP/bdlcc/ObjectPool/ResetterType.adoc[`ResetterType`] | Type of the resetter functor used by this pool. |=== == Member Functions [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bdlcc/ObjectPool/2constructor-04.adoc[`ObjectPool`] [.small]#[constructor]# | Constructors | xref:BloombergLP/bdlcc/ObjectPool/2destructor.adoc[`~ObjectPool`] [.small]#[destructor]# [.small]#[virtual]# | Destroy this object pool. All objects created by this pool are destroyed (even if some of them are still in use) and memory is reclaimed. | xref:BloombergLP/bdlcc/ObjectPool/createObject.adoc[`createObject`] [.small]#[virtual]# | This concrete implementation of `bdlma::Factory::createObject` invokes `getObject`. This should not be invoked directly. | 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. If this pool is empty, it is replenished according to the strategy specified at the pool construction (or an implementation‐defined strategy if none was provided). | xref:BloombergLP/bdlcc/ObjectPool/increaseCapacity.adoc[`increaseCapacity`] | Create the specified `numObjects` objects and add them to this object pool. The behavior is undefined unless `0 <= numObjects`. | xref:BloombergLP/bdlcc/ObjectPool/numAvailableObjects.adoc[`numAvailableObjects`] | Return a _snapshot_ of the number of objects available in this pool. | xref:BloombergLP/bdlcc/ObjectPool/numObjects.adoc[`numObjects`] | Return the (instantaneous) number of objects managed by this pool. This includes both the objects available in the pool and the objects that were allocated from the pool and not yet released. | xref:BloombergLP/bdlcc/ObjectPool/releaseObject.adoc[`releaseObject`] | Return the specified `object` back to this object pool. Invoke the RESETTER specified at construction, or the default RESETTER if none was provided, before making the object available for reuse. Note that if RESETTER is the default type (`ObjectPoolFunctors::Nil`), then this method should be invoked to return only _valid_ objects because the pool uses the released objects to satisfy further `getObject` requests. The behavior is undefined unless the `object` was obtained from this object pool's `getObject` method and is not already in a released state. | xref:BloombergLP/bdlcc/ObjectPool/reserveCapacity.adoc[`reserveCapacity`] | Create enough objects to satisfy requests for at least the specified `numObjects` objects before the next replenishment. The behavior is undefined unless `0 <= numObjects`. Note that this method is different from `increaseCapacity` in that the number of created objects may be less than `numObjects`. | xref:BloombergLP/bdlcc/ObjectPool/2conversion.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration<ObjectPool, UsesBslmaAllocator>`] | Declare that this type uses a `bslma` allocator. |=== == Friends [cols="1,4"] |=== | Name| Description | `BloombergLP::bdlcc::ObjectPool::AutoCleanup` | |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#