template<class TYPE, class CREATOR = ObjectPoolFunctors::DefaultCreator, class RESETTER = ObjectPoolFunctors::Nil<TYPE>>
class bdlcc::ObjectPool< TYPE, CREATOR, RESETTER >
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.
See bdlcc_objectpool
|
| | BSLMF_NESTED_TRAIT_DECLARATION (ObjectPool, bslma::UsesBslmaAllocator) |
| |
| | ObjectPool (int growBy=-1, bslma::Allocator *basicAllocator=0) |
| |
| | ObjectPool (const CREATOR &objectCreator, int growBy, bslma::Allocator *basicAllocator=0) |
| |
| | ObjectPool (const CREATOR &objectCreator, bslma::Allocator *basicAllocator=0) |
| |
| | ObjectPool (const CREATOR &objectCreator, const RESETTER &objectResetter, int growBy=-1, bslma::Allocator *basicAllocator=0) |
| |
| template<class ANYPROTO > |
| | ObjectPool (const bsl::function< ANYPROTO > &objectCreator, int growBy, bslma::Allocator *basicAllocator=0) |
| |
| template<class ANYPROTO > |
| | ObjectPool (const bsl::function< ANYPROTO > &objectCreator, bslma::Allocator *basicAllocator=0) |
| |
| virtual | ~ObjectPool () |
| |
| TYPE * | getObject () |
| |
| void | increaseCapacity (int numObjects) |
| |
| void | releaseObject (TYPE *object) |
| |
| void | reserveCapacity (int numObjects) |
| |
| int | numAvailableObjects () const |
| |
| int | numObjects () const |
| |
| virtual TYPE * | createObject () |
| |
| virtual void | deleteObject (TYPE *object) |
| |
| virtual | ~Factory () |
| |
| virtual | ~Deleter () |
| |
template<class TYPE , class CREATOR , class RESETTER >
Create an object pool that invokes the default constructor of the the parameterized TYPE to construct objects. When the pool is depleted, it will increase its capacity according to the optionally specified growBy value. If growBy is positive, the pool replenishes itself with at least growBy new objects. If growBy is negative, the amount of increase begins at -growBy and grows geometrically up to an implementation-defined maximum. When objects are returned to the pool, the default value of RESETTER is invoked with a pointer to the returned object to restore the object to a reusable state. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used.
- Precondition
- The behavior is undefined unless
0 != growBy.
template<class TYPE , class CREATOR , class RESETTER >
Create an object pool that uses the specified objectCreator (encapsulating the construction of objects) to create objects. The client must ensure that objectCreator(buf, alloc) creates an object at memory location buf using alloc to supply memory. When the pool is depleted, it will grow capacity according to the optionally specified growBy value. If growBy is positive, the pool replenishes itself with at least growBy new objects. If growBy is negative, the amount of increase begins at -growBy and grows geometrically up to an implementation-defined maximum. When objects are returned to the pool, the default value of RESETTER is invoked with a pointer to the returned object to restore the object to a reusable state. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used.
- Precondition
- The behavior is undefined unless
0 != growBy.
template<class TYPE , class CREATOR , class RESETTER >
| bdlcc::ObjectPool< TYPE, CREATOR, RESETTER >::ObjectPool |
( |
const CREATOR & |
objectCreator, |
|
|
const RESETTER & |
objectResetter, |
|
|
int |
growBy = -1, |
|
|
bslma::Allocator * |
basicAllocator = 0 |
|
) |
| |
Create an object pool that uses the specified objectCreator (encapsulating the construction of objects) to create objects. The client must ensure that objectCreator(buf, alloc) creates an object at memory location buf using alloc to supply memory. When the pool is depleted, it will increase its capacity according to the optionally specified growBy value. If growBy is positive, the pool replenishes itself with at least growBy new objects. If growBy is negative, the amount of increase begins at -growBy and grows geometrically up to an implementation-defined maximum. When objects are returned to the pool, the specified objectResetter is invoked with a pointer to the returned object to restore the object to a reusable state. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used.
- Precondition
- The behavior is undefined unless
0 != growBy.