#include <cachweak.h>
Inheritance diagram for ObjectCacheWeakest:
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) |
Definition at line 120 of file cachweak.h.
|
default constructor for ObjectCacheWeakest Note:
Definition at line 126 of file cachweak.cpp. 00127 { 00128 m_Ceiling = 0; 00129 }
|
|
constructor for ObjectCacheWeakest Note:
Definition at line 142 of file cachweak.cpp. 00143 { 00144 m_Ceiling = ceiling; 00145 }
|
|
destructor for ObjectCacheWeakest Note:
Definition at line 157 of file cachweak.cpp.
|
|
|
|
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:.
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 }
|