#include <cachrand.h>
Inheritance diagram for ObjectCacheRandom:
Public Member Functions | |
ObjectCacheRandom () | |
default constructor for ObjectCache Note: | |
ObjectCacheRandom (UINT32 ceiling) | |
constructor for ObjectCacheRandom. Set the size of the cache. Note: | |
~ObjectCacheRandom () | |
destructor for ObjectCache Note: | |
Protected Member Functions | |
BOOL | DeleteObject () |
delete an object in the cache according a radom algorithm. Note: | |
Private Member Functions | |
CC_DECLARE_DYNCREATE (ObjectCacheRandom) |
Definition at line 119 of file cachrand.h.
|
default constructor for ObjectCache Note:
Definition at line 128 of file cachrand.cpp. 00129 { 00130 m_Ceiling = 0; 00131 }
|
|
constructor for ObjectCacheRandom. Set the size of the cache. Note:
Definition at line 144 of file cachrand.cpp. 00145 { 00146 m_Ceiling = ceiling; 00147 }
|
|
destructor for ObjectCache Note:
Definition at line 159 of file cachrand.cpp.
|
|
|
|
delete an object in the cache according a radom algorithm. Note:
Reimplemented from ObjectCache. Definition at line 176 of file cachrand.cpp. 00177 { 00178 if (m_NumObjects == 0) 00179 return FALSE; 00180 00181 srand((unsigned)time(NULL)); 00182 BOOL ok = FALSE; 00183 WORD Factory = 0; 00184 CachedObject* pObj = NULL; 00185 00186 do 00187 { 00188 WORD hObj = rand() % m_HandleFactory + 1; // generate a handle 00189 Factory++; // count the number of generated numbers 00190 00191 pObj = LookUp(hObj); // look up in the hash table 00192 ok = (pObj != NULL); 00193 00194 if(ok) 00195 { 00196 Remove(hObj); // remove from the hash table 00197 m_NumObjects--; // decrease the number of objects 00198 m_CurrentSize -= pObj->GetSize(); // decrease the used space of cache 00199 } 00200 } 00201 while (!ok && Factory<=m_HandleFactory); 00202 00203 //if(ok && Factory<=HandleFactory) 00204 if(ok) 00205 { 00206 delete pObj; 00207 pObj = NULL; 00208 return TRUE; 00209 } 00210 00211 return FALSE; 00212 }
|