NCBI C++ ToolKit
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
CResourcePool_Base< Value, Lock, CF > Class Template Reference

Search Toolkit Book for CResourcePool_Base

General purpose resource pool (base class, sans default constructor arguments for maximum versatility). More...

#include <util/resource_pool.hpp>

+ Inheritance diagram for CResourcePool_Base< Value, Lock, CF >:
+ Collaboration diagram for CResourcePool_Base< Value, Lock, CF >:

Public Types

typedef Value TValue
 
typedef Lock TLock
 
typedef Lock::TReadLockGuard TReadLockGuard
 
typedef Lock::TWriteLockGuard TWriteLockGuard
 
typedef CF TClassFactory
 
typedef Value * TValuePtr
 
typedef deque< Value * > TPoolList
 

Public Member Functions

 CResourcePool_Base (size_t capacity_upper_limit, const TClassFactory &cf)
 Construction. More...
 
 ~CResourcePool_Base ()
 
size_t GetCapacityLimit () const
 Return max pool size. More...
 
void SetCapacityLimit (size_t capacity_upper_limit)
 Set upper limit for pool capacity (everything above this is deleted) More...
 
size_t GetSize () const
 Get current pool size (number of objects in the pool) More...
 
Value * Get ()
 Get object from the pool. More...
 
Value * GetIfAvailable ()
 Get object from the pool if there is a vacancy, otherwise returns NULL. More...
 
void Put (Value *v)
 Put object into the pool. More...
 
void Return (Value *v)
 
Value * Forget (Value *v)
 Makes the pool to forget the object. More...
 
void ForgetAll ()
 Makes pool to forget all objects. More...
 
void FreeAll ()
 Free all pool objects. More...
 
TPoolListGetFreeList ()
 Get internal list of free objects. More...
 
const TPoolListGetFreeList () const
 Get internal list of free objects. More...
 

Protected Member Functions

 CResourcePool_Base (const CResourcePool_Base &)
 
CResourcePool_Baseoperator= (const CResourcePool_Base &)
 

Protected Attributes

TPoolList m_FreeObjects
 
TLock m_Lock
 
TClassFactory m_CF
 
size_t m_UpperLimit
 Upper limit how much to pool. More...
 

Detailed Description

template<class Value, class Lock = CNoLock, class CF = CResoursePool_NewClassFactory<Value>>
class CResourcePool_Base< Value, Lock, CF >

General purpose resource pool (base class, sans default constructor arguments for maximum versatility).

Intended use is to store reusable objects. Pool frees all vacant objects only upon pools destruction. Subsequent Get/Put calls does not result in objects reallocations and re-initializations. (So the prime target is performance optimization).

Class can be used synchronized across threads (use CFastMutex as Lock parameter)

Default creation/destruction protocol is C++ new/delete. Can be overloaded using CF parameter

Definition at line 73 of file resource_pool.hpp.


The documentation for this class was generated from the following file:
Modified on Wed Sep 04 15:00:09 2024 by modify_doxy.py rev. 669887