Main Page Namespace List Class Hierarchy Compound List File List Namespace Members Compound Members Related Pages
nevelex_util::ObjectPool Class Template Reference#include <ObjectPool.h>
Inheritance diagram for nevelex_util::ObjectPool:
[legend]Collaboration diagram for nevelex_util::ObjectPool:
[legend]List of all members.
Detailed Description
template<class T> class nevelex_util::ObjectPool
Template class used to as the basis for object pooling (LIFO). Only use this class if the process of creating a new object is slower than pooling, because pooling is time consuming due to all the synchronization required.
Supports the following operations:
- checkOut - retrieves a T object from the pool. Creates a new object if none are available. Requires synchronization.
- checkOutFast - fast retrieval of a T object. Does not use synchronization. Same as doing a new.
- checkIn - return a T object in to the pool and records its check in time. Requires synchronization.
- checkInFast - fast return of a T object. Does not use synchronization. Same as doing a delete.
- cleanUp - removes any objects in the pool that have been in the pool past their expiration time. Each template object implementation must support a zero argument constructor.
-
Attention:
-
Classes used within the object pool must have a zero-argument constructor because the pool creates the object internally.
-
Todo:
-
Allow for a couple of different usages scenarios: -let user add their own objects in to the pool. -let user limit number of objects in the pool.
-
Author:
-
Michel Dalal
-
Date:
-
Mon Sep 23 2002
-
Version:
-
1.0: Initial version.
-
1.1.0 06/20/2003: Support for Mac OS X.
-
1.1.1 07/02/2003: Fixed namespace error for hash_set.
-
1.1.2 07/07/2003: Renamed define from HASH_SET_NAMESPACE to HASH_NAMESPACE.
-
1.1.3 09/05/2003: Fixed if check around hashset include.
Constructor & Destructor Documentation
|
template<class T> |
|
nevelex_util::ObjectPool<T>::ObjectPool<T> (
|
time_t expiresTime ) [inline]
|
|
|
|
Creates the object pool. Starts the thread that handles cleaning out the expired objects. -
Parameters:
-
| expiresTime
|
time in seconds for a |
|
|
template<class T> |
|
nevelex_util::ObjectPool<T>::~ObjectPool<T> (
|
) [inline, virtual]
|
|
|
|
Destroys the object pool. Deletes any objects remaining in the |
|
template<class T> |
|
nevelex_util::ObjectPool<T>::ObjectPool<T> (
|
const ObjectPool< T > & m ) [inline]
|
|
|
|
Copy constructor. -
Parameters:
-
| m
|
the source object for the copy constructor. |
|
Member Function Documentation
|
template<class T> |
|
void nevelex_util::ObjectPool<T>::checkIn (
|
T * object ) [inline]
|
|
|
|
Returns an object back in to the pool. An exception is thrown if the object being returned was never checkedOut. All checked out objects must be checked back in! -
Parameters:
-
| object
|
the object to return to the object pool. |
-
Exceptions:
-
| std::runtime_error
|
if the object is not in the locked object pool. |
-
See also:
-
checkOut
|
|
template<class T> |
|
void nevelex_util::ObjectPool<T>::checkInFast (
|
T * t ) [inline]
|
|
|
|
Does a fast check int of an object. Always deletes the supplied object and does not do any synchronization. All checked out objects must be checked back in!
-
Attention:
-
Only use this method if checkOutFast was used to retrieve the object.
-
Returns:
-
returns a checked out template object.
-
See also:
-
checkOutFast
|
|
template<class T> |
|
T * nevelex_util::ObjectPool<T>::checkOut (
|
void ) [inline]
|
|
|
|
Checks out an object from the pool. If it does not exist, a new object is added to the pool and immediately checked out. All checked out objects must be checked back in!
-
Returns:
-
returns a checked out template object.
-
Exceptions:
-
| std::runtime_error
|
if the creation of a new template object failed. |
-
See also:
-
checkIn
|
|
template<class T> |
|
T * nevelex_util::ObjectPool<T>::checkOutFast (
|
void ) [inline]
|
|
|
|
Does a fast check out of an object. Always creates a new object and does not do any synchronization. All checked out objects must be checked back in!
-
Returns:
-
returns a checked out template object.
-
Exceptions:
-
| std::runtime_error
|
if the creation of a new template object failed. |
-
Attention:
-
Only use checkInFast to check in the object.
-
See also:
-
checkInFast
|
|
template<class T> |
|
void nevelex_util::ObjectPool<T>::cleanUp (
|
) [inline, virtual]
|
|
|
|
Method used to clean up any unneeded objects in the pool. When a checked in object has been unused for greater than or equal to expiration seconds, it is removed and deleted from the pool automatically.
-
Attention:
-
This method does not ever need to be called. It is called automatically by the ObjectPoolManager.
Reimplemented from nevelex_util::ManagedPool. |
|
template<class T> |
|
const ObjectPool< T > & nevelex_util::ObjectPool<T>::operator= (
|
const ObjectPool< T > & rhs ) [inline]
|
|
|
|
Assignment operator -
Parameters:
-
| rhs
|
the right hand side of the operation. |
|
The documentation for this class was generated from the following file:
|
 |