BloombergLP::bdlcc::ObjectPool

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>

template<
    class TYPE,
    class CREATOR = ObjectPoolFunctors::DefaultCreator,
    class RESETTER = ObjectPoolFunctors::Nil<TYPE>>
class ObjectPool
    : public bdlma::Factory<TYPE>

Base Classes

NameDescription
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

NameDescription
CreatorType Type of the creator functor used by this pool.
ResetterType Type of the resetter functor used by this pool.

Member Functions

NameDescription
ObjectPool [constructor]Constructors
~ObjectPool [destructor] [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.
createObject [virtual]This concrete implementation of bdlma::Factory::createObject invokes getObject. This should not be invoked directly.
deleteObject deleteObject overloads
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).
increaseCapacity Create the specified numObjects objects and add them to this object pool. The behavior is undefined unless 0 <= numObjects.
numAvailableObjects Return a snapshot of the number of objects available in this pool.
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.
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.
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.
operator BloombergLP::bslmf::NestedTraitDeclaration<ObjectPool, UsesBslmaAllocator> Declare that this type uses a bslma allocator.

Friends

NameDescription
BloombergLP::bdlcc::ObjectPool::AutoCleanup