ObjectCacheWeakest Class Reference

Provides a delete algorithm cache replacement policy according to the size of the object. See also: class ObjectCache. More...

#include <cachweak.h>

Inheritance diagram for ObjectCacheWeakest:

ObjectCache CCObject SimpleCCObject List of all members.

Public Member Functions

 ObjectCacheWeakest ()
 default constructor for ObjectCacheWeakest Note:
 ObjectCacheWeakest (UINT32 ceiling)
 constructor for ObjectCacheWeakest Note:
 ~ObjectCacheWeakest ()
 destructor for ObjectCacheWeakest Note:

Protected Member Functions

BOOL DeleteObject ()
 Provides a delete alorithm according to the size of the object and an importance factor called "Immortal" (TRUE or FALSE). Bigger objects are deleted first, but an object which Immortal factor is set to TRUE will not be deleted. Note:.

Private Member Functions

 CC_DECLARE_DYNCREATE (ObjectCacheWeakest)

Detailed Description

Provides a delete algorithm cache replacement policy according to the size of the object. See also: class ObjectCache.

Author:
Olivier_Gascoin (Xara Group Ltd) <camelotdev@xara.com>
Date:
24/01/97

Definition at line 120 of file cachweak.h.


Constructor & Destructor Documentation

ObjectCacheWeakest::ObjectCacheWeakest  ) 
 

default constructor for ObjectCacheWeakest Note:

Author:
Olivier_Gascoin (Xara Group Ltd) <camelotdev@xara.com>
Date:
20/01/97
See also:
ObjectCache

Definition at line 126 of file cachweak.cpp.

00127 {
00128     m_Ceiling = 0;
00129 }

ObjectCacheWeakest::ObjectCacheWeakest UINT32  ceiling  ) 
 

constructor for ObjectCacheWeakest Note:

Author:
Olivier_Gascoin (Xara Group Ltd) <camelotdev@xara.com>
Date:
20/01/97
Parameters:
ceiling,: size of the cache [INPUTS]
See also:

Definition at line 142 of file cachweak.cpp.

00143 {
00144     m_Ceiling = ceiling;
00145 }

ObjectCacheWeakest::~ObjectCacheWeakest  ) 
 

destructor for ObjectCacheWeakest Note:

Author:
Olivier_Gascoin (Xara Group Ltd) <camelotdev@xara.com>
Date:
20/01/97
See also:

Definition at line 157 of file cachweak.cpp.

00158 {
00159 }


Member Function Documentation

ObjectCacheWeakest::CC_DECLARE_DYNCREATE ObjectCacheWeakest   )  [private]
 

BOOL ObjectCacheWeakest::DeleteObject  )  [protected, virtual]
 

Provides a delete alorithm according to the size of the object and an importance factor called "Immortal" (TRUE or FALSE). Bigger objects are deleted first, but an object which Immortal factor is set to TRUE will not be deleted. Note:.

Author:
Olivier_Gascoin (Xara Group Ltd) <camelotdev@xara.com>
Date:
21/01/97
Returns:
TRUE if success
See also:

Reimplemented from ObjectCache.

Definition at line 176 of file cachweak.cpp.

00177 {
00178     if(m_NumObjects == 0)
00179         return FALSE;   // empty cache
00180 
00181     CachedObject* pWeakest = NULL;
00182     INT32 handle = 1;
00183 
00184     // Get the first non immortal object 
00185     while((pWeakest == NULL) && (handle<=m_HandleFactory))
00186     {
00187         pWeakest = LookUp(handle);
00188         if (pWeakest != NULL)
00189         {
00190             if (pWeakest->IsImmortal())     // it shouldn't be immortal
00191                 pWeakest = NULL;
00192         }
00193         handle++;
00194     }
00195 
00196     if(pWeakest == NULL)
00197         return FALSE;                       // all objects are immortal 
00198 
00199     // Get the size of the object
00200     UINT32 WeakestChance = pWeakest->GetSize();
00201 
00202     // save a copy of the handle
00203     WORD CurrentHandle = handle;
00204 
00205     // now look up for the biggest object that will be deleted from the cache.
00206     for(handle=1;handle<m_HandleFactory;handle++)
00207     {
00208         CachedObject* pWeakestTemp = LookUp(handle);
00209         if(pWeakestTemp != NULL)
00210         {
00211             if((pWeakestTemp->GetSize()>WeakestChance) && (!pWeakestTemp->IsImmortal()))
00212             {
00213                 CurrentHandle = handle;
00214                 pWeakest = pWeakestTemp;
00215                 WeakestChance = pWeakest->GetSize();
00216             }
00217         }
00218     }
00219 
00220     // Delete the weakest Object
00221     m_NumObjects--;
00222     Remove(CurrentHandle);
00223     //Remove(pWeakest->GetHandle());            // Delete from the hash table
00224     m_CurrentSize -= pWeakest->GetSize();   // change the cache size
00225     delete pWeakest;
00226 
00227     return TRUE;
00228 }


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:57:16 2007 for Camelot by  doxygen 1.4.4