Quick Links:

bal | bbl | bdl | bsl

Classes | Public Types | Public Member Functions | Friends

bdlcc::ObjectPool< TYPE, CREATOR, RESETTER > Class Template Reference

#include <bdlcc_objectpool.h>

Inheritance diagram for bdlcc::ObjectPool< TYPE, CREATOR, RESETTER >:
bdlma::Factory< TYPE > bdlma::Deleter< TYPE >

List of all members.

Classes

class  AutoCleanup
union  BlockNode
union  ObjectNode

Public Types

typedef RESETTER ResetterType
typedef CREATOR CreatorType

Public Member Functions

 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)

Friends

class AutoCleanup

Detailed Description

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 Component bdlcc_objectpool


Member Typedef Documentation

template<class TYPE, class CREATOR = ObjectPoolFunctors::DefaultCreator, class RESETTER = ObjectPoolFunctors::Nil<TYPE>>
typedef RESETTER bdlcc::ObjectPool< TYPE, CREATOR, RESETTER >::ResetterType
template<class TYPE, class CREATOR = ObjectPoolFunctors::DefaultCreator, class RESETTER = ObjectPoolFunctors::Nil<TYPE>>
typedef CREATOR bdlcc::ObjectPool< TYPE, CREATOR, RESETTER >::CreatorType

Constructor & Destructor Documentation

template<class TYPE, class CREATOR = ObjectPoolFunctors::DefaultCreator, class RESETTER = ObjectPoolFunctors::Nil<TYPE>>
bdlcc::ObjectPool< TYPE, CREATOR, RESETTER >::ObjectPool ( int  growBy = -1,
bslma::Allocator basicAllocator = 0 
) [explicit]

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. The behavior is undefined unless 0 != growBy.

template<class TYPE, class CREATOR = ObjectPoolFunctors::DefaultCreator, class RESETTER = ObjectPoolFunctors::Nil<TYPE>>
bdlcc::ObjectPool< TYPE, CREATOR, RESETTER >::ObjectPool ( const CREATOR &  objectCreator,
int  growBy,
bslma::Allocator basicAllocator = 0 
) [explicit]
template<class TYPE, class CREATOR = ObjectPoolFunctors::DefaultCreator, class RESETTER = ObjectPoolFunctors::Nil<TYPE>>
bdlcc::ObjectPool< TYPE, CREATOR, RESETTER >::ObjectPool ( const CREATOR &  objectCreator,
bslma::Allocator basicAllocator = 0 
) [explicit]

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. The behavior is undefined unless 0 != growBy.

template<class TYPE, class CREATOR = ObjectPoolFunctors::DefaultCreator, class RESETTER = ObjectPoolFunctors::Nil<TYPE>>
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. The behavior is undefined unless 0 != growBy.

template<class TYPE, class CREATOR = ObjectPoolFunctors::DefaultCreator, class RESETTER = ObjectPoolFunctors::Nil<TYPE>>
template<class ANYPROTO >
bdlcc::ObjectPool< TYPE, CREATOR, RESETTER >::ObjectPool ( const bsl::function< ANYPROTO > &  objectCreator,
int  growBy,
bslma::Allocator basicAllocator = 0 
) [explicit]
template<class TYPE, class CREATOR = ObjectPoolFunctors::DefaultCreator, class RESETTER = ObjectPoolFunctors::Nil<TYPE>>
template<class ANYPROTO >
bdlcc::ObjectPool< TYPE, CREATOR, RESETTER >::ObjectPool ( const bsl::function< ANYPROTO > &  objectCreator,
bslma::Allocator basicAllocator = 0 
) [explicit]

DEPRECATED Use a creator of the parameterized CREATOR type.

template<class TYPE, class CREATOR = ObjectPoolFunctors::DefaultCreator, class RESETTER = ObjectPoolFunctors::Nil<TYPE>>
virtual bdlcc::ObjectPool< TYPE, CREATOR, RESETTER >::~ObjectPool (  )  [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.


Member Function Documentation

template<class TYPE, class CREATOR = ObjectPoolFunctors::DefaultCreator, class RESETTER = ObjectPoolFunctors::Nil<TYPE>>
bdlcc::ObjectPool< TYPE, CREATOR, RESETTER >::BSLMF_NESTED_TRAIT_DECLARATION ( ObjectPool< TYPE, CREATOR, RESETTER >  ,
bslma::UsesBslmaAllocator   
)
template<class TYPE, class CREATOR = ObjectPoolFunctors::DefaultCreator, class RESETTER = ObjectPoolFunctors::Nil<TYPE>>
TYPE* bdlcc::ObjectPool< TYPE, CREATOR, RESETTER >::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).

template<class TYPE, class CREATOR = ObjectPoolFunctors::DefaultCreator, class RESETTER = ObjectPoolFunctors::Nil<TYPE>>
void bdlcc::ObjectPool< TYPE, CREATOR, RESETTER >::increaseCapacity ( int  numObjects  ) 

Create the specified numObjects objects and add them to this object pool. The behavior is undefined unless 0 <= numObjects.

template<class TYPE, class CREATOR = ObjectPoolFunctors::DefaultCreator, class RESETTER = ObjectPoolFunctors::Nil<TYPE>>
void bdlcc::ObjectPool< TYPE, CREATOR, RESETTER >::releaseObject ( TYPE *  object  ) 

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.

template<class TYPE, class CREATOR = ObjectPoolFunctors::DefaultCreator, class RESETTER = ObjectPoolFunctors::Nil<TYPE>>
void bdlcc::ObjectPool< TYPE, CREATOR, RESETTER >::reserveCapacity ( int  numObjects  ) 

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.

template<class TYPE, class CREATOR = ObjectPoolFunctors::DefaultCreator, class RESETTER = ObjectPoolFunctors::Nil<TYPE>>
int bdlcc::ObjectPool< TYPE, CREATOR, RESETTER >::numAvailableObjects (  )  const

Return a snapshot of the number of objects available in this pool.

template<class TYPE, class CREATOR = ObjectPoolFunctors::DefaultCreator, class RESETTER = ObjectPoolFunctors::Nil<TYPE>>
int bdlcc::ObjectPool< TYPE, CREATOR, RESETTER >::numObjects (  )  const

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.

template<class TYPE, class CREATOR = ObjectPoolFunctors::DefaultCreator, class RESETTER = ObjectPoolFunctors::Nil<TYPE>>
virtual TYPE* bdlcc::ObjectPool< TYPE, CREATOR, RESETTER >::createObject (  )  [virtual]

This concrete implementation of bdlma::Factory::createObject invokes getObject. This should not be invoked directly.

Implements bdlma::Factory< TYPE >.

template<class TYPE, class CREATOR = ObjectPoolFunctors::DefaultCreator, class RESETTER = ObjectPoolFunctors::Nil<TYPE>>
virtual void bdlcc::ObjectPool< TYPE, CREATOR, RESETTER >::deleteObject ( TYPE *  object  )  [virtual]

This concrete implementation of bdlma::Factory::deleteObject invokes releaseObject on the specified object, returning it to this pool. The behavior is undefined if object is already in a released state. Note that this does not destroy the object and should not be invoked directly.

Implements bdlma::Factory< TYPE >.


Friends And Related Function Documentation

template<class TYPE, class CREATOR = ObjectPoolFunctors::DefaultCreator, class RESETTER = ObjectPoolFunctors::Nil<TYPE>>
friend class AutoCleanup [friend]

The documentation for this class was generated from the following file: