Library: Foundation
Package: Core
Header: Poco/ObjectPool.h
An ObjectPool manages a pool of objects of a certain class.
The number of objects managed by the pool can be restricted.
When an object is requested from the pool:
When an object is returned to the pool:
Member Functions: activateObject, available, borrowObject, capacity, peakCapacity, returnObject, size
ObjectPool(
std::size_t capacity,
std::size_t peakCapacity
);
Creates a new ObjectPool with the given capacity and peak capcacity.
The PoolableObjectFactory must have a public default constructor.
ObjectPool(
const F & factory,
std::size_t capacity,
std::size_t peakCapacity
);
Creates a new ObjectPool with the given PoolableObjectFactory, capacity and peak capacity. The PoolableObjectFactory must have a public copy constructor.
~ObjectPool();
Destroys the ObjectPool.
std::size_t available() const;
P borrowObject();
Obtains an object from the pool, or creates a new object if possible.
Returns null if no object is available.
If activating the object fails, the object is destroyed and the exception is passed on to the caller.
std::size_t capacity() const;
std::size_t peakCapacity() const;
void returnObject(
P pObject
);
Returns an object to the pool.
std::size_t size() const;
P activateObject(
P pObject
);