Poco

template < class C, class P = C *, class F = PoolableObjectFactory < C, P > >

class ObjectPool

Library: Foundation
Package: Core
Header: Poco/ObjectPool.h

Description

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 Summary

Member Functions: activateObject, available, borrowObject, capacity, peakCapacity, returnObject, size

Constructors

ObjectPool inline

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 inline

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.

Destructor

~ObjectPool inline

~ObjectPool();

Destroys the ObjectPool.

Member Functions

available inline

std::size_t available() const;

borrowObject inline

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.

capacity inline

std::size_t capacity() const;

peakCapacity inline

std::size_t peakCapacity() const;

returnObject inline

void returnObject(
    P pObject
);

Returns an object to the pool.

size inline

std::size_t size() const;

activateObject protected inline

P activateObject(
    P pObject
);