NCBI C++ ToolKit
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
CObjPool< TObjType, TObjFactory > Class Template Reference

Search Toolkit Book for CObjPool

General object pool. More...

#include <corelib/obj_pool.hpp>

+ Inheritance diagram for CObjPool< TObjType, TObjFactory >:
+ Collaboration diagram for CObjPool< TObjType, TObjFactory >:

Public Types

typedef deque< TObjType * > TObjectsList
 
typedef TObjType TObjectType
 Synonym to be able to use outside of the pool. More...
 

Public Member Functions

 CObjPool (size_t max_storage_size=size_t(-1))
 Create object pool. More...
 
 CObjPool (const TObjFactory &factory, size_t max_storage_size=size_t(-1))
 Create object pool. More...
 
 ~CObjPool (void)
 Destroy object pool and all objects it owns. More...
 
TObjType * Get (void)
 Get object from the pool, create if necessary. More...
 
void Return (TObjType *obj)
 Return object to the pool for future use. More...
 
void Clear (void)
 Delete all objects returned to the pool so far and clean it. More...
 
size_t GetMaxStorageSize (void) const
 Get maximum number of unused objects that can be stored in the pool. More...
 
void SetMaxStorageSize (size_t max_storage_size)
 Set maximum number of unused objects that can be stored in the pool. More...
 

Private Member Functions

 CObjPool (const CObjPool &)
 
CObjPooloperator= (const CObjPool &)
 

Private Attributes

size_t m_MaxStorage
 Maximum number of unused objects that can be stored in the pool. More...
 
TObjFactory m_Factory
 Object factory. More...
 
CSpinLock m_ObjLock
 Lock object to change the pool. More...
 
TObjectsList m_FreeObjects
 List of unused objects. More...
 

Detailed Description

template<class TObjType, class TObjFactory = CObjFactory_New<TObjType>>
class CObjPool< TObjType, TObjFactory >

General object pool.

Parameters
TObjTypeType of objects in the pool (any type, not necessarily inherited from CObject). Pool holds pointers to objects, so they shouldn't be copyable.
TObjFactoryType of object factory, representing the policy of how objects created and how they deleted. Factory should implement 2 methods - CreateObject() and DeleteObject(). CreateObject() should get no parameters, create new object and return pointer to it. Returned pointer should be always non-NULL. DeleteObject() should take one parameter (pointer to object) and should delete given object.
TLockType of the lock used in the pool to protect against multi-threading issues. If no multi-threading protection is necessary CNoLock can be used.

Definition at line 65 of file obj_pool.hpp.


The documentation for this class was generated from the following file:
Modified on Tue Jun 18 13:37:54 2024 by modify_doxy.py rev. 669887