#include <objcache.h>
Inheritance diagram for ObjectCache:
Public Member Functions | |
ObjectCache () | |
default constructor for ObjectCache Note: | |
ObjectCache (UINT32 ceiling) | |
constructor for ObjectCache, set the cache size. | |
~ObjectCache () | |
destructor for ObjectCache Note: | |
virtual WORD | Add (CachedObject *pObj) |
Add an object in the Hash table of the cache Note:. | |
virtual CachedObject * | LookUp (WORD hObj) |
LookUp in the hash table. | |
virtual BOOL | Remove (WORD hObj) |
Remove a key from the hash table Note:. | |
virtual BOOL | SetMaxCacheSize (UINT32 NewCeiling) |
dynamically change the size (in bytes) of the Cache. Note: | |
Protected Member Functions | |
virtual BOOL | MakeRoomFor (CachedObject *pObj) |
make room for another object by deleting old objects if the cache is full Note: | |
virtual BOOL | DeleteObject () |
virtual function. This is the base class delete function. All algorithms are implemented in the derived classes such as ObjectCacheRandom...etc. Note: | |
Protected Attributes | |
UINT32 | m_Ceiling |
UINT32 | m_CurrentSize |
WORD | m_NumObjects |
std::map< WORD, PVOID > | m_ObjectMap |
WORD | m_HandleFactory |
Private Member Functions | |
CC_DECLARE_DYNCREATE (ObjectCache) |
Definition at line 121 of file objcache.h.
|
default constructor for ObjectCache Note:
Definition at line 130 of file objcache.cpp. 00131 { 00132 // Compute the available amount of memory 00133 /*TunedMemory* pTuneMem = GetTunedMemManager(); 00134 if (pTuneMem != NULL) 00135 Ceiling = pTuneMem->GetAvailableTunedMem();*/ 00136 00137 m_NumObjects = 0; 00138 m_HandleFactory = 1; 00139 m_CurrentSize = 0; 00140 }
|
|
constructor for ObjectCache, set the cache size.
Definition at line 153 of file objcache.cpp. 00154 { 00155 m_Ceiling = ceiling; 00156 m_NumObjects = 0; 00157 m_HandleFactory = 1; // we don't start from 0 00158 m_CurrentSize = 0; 00159 }
|
|
destructor for ObjectCache Note:
Definition at line 171 of file objcache.cpp.
|
|
Add an object in the Hash table of the cache Note:.
Definition at line 212 of file objcache.cpp. 00213 { 00214 ERROR3IF(pObj==NULL, "Error: the object to cache can't be NULL"); 00215 00216 if (pObj == NULL) 00217 return 0; 00218 00219 // MYTRACE( _T("ObjectCache::Add()\n")); 00220 00221 // if we can make room for the object then assign the object a unique handle and cache it 00222 if (MakeRoomFor(pObj)) 00223 { 00224 CACHE_HANDLE hObj = m_HandleFactory++; 00225 00226 pObj->StoreHandle(hObj); // store the CachedObject Handle 00227 m_NumObjects++; // Increase the number of objects 00228 m_CurrentSize += pObj->GetSize(); // Increase the space used 00229 m_ObjectMap[hObj] = pObj; // set the object in the hash table 00230 return hObj; 00231 } 00232 00233 return 0; 00234 }
|
|
|
|
virtual function. This is the base class delete function. All algorithms are implemented in the derived classes such as ObjectCacheRandom...etc. Note:
Reimplemented in ObjectCacheFIFO, ObjectCacheRandom, and ObjectCacheWeakest. Definition at line 340 of file objcache.cpp. 00341 { 00342 return TRUE; 00343 }
|
|
LookUp in the hash table.
Definition at line 294 of file objcache.cpp. 00295 { 00296 // void* pObjMap = NULL; 00297 00298 std::map<WORD, PVOID>::iterator iter = m_ObjectMap.find( hObj ); 00299 if( m_ObjectMap.end() != iter ) 00300 return (CachedObject *)iter->second; 00301 00302 return NULL; 00303 }
|
|
make room for another object by deleting old objects if the cache is full Note:
Definition at line 250 of file objcache.cpp. 00251 { 00252 ERROR3IF(pObj==NULL, "Error: the object to cache can't be NULL"); 00253 00254 if (pObj == NULL) 00255 return FALSE; 00256 00257 // is there room in the cache or do we have to free some memory ? 00258 if (pObj->GetSize() + m_CurrentSize <= m_Ceiling) 00259 return TRUE; // enough room 00260 00261 // is the cache big enough ? 00262 if (pObj->GetSize() > m_Ceiling) 00263 return FALSE; // the object is bigger than the cache size 00264 00265 // Scan the cache deleting objects until there is room 00266 BOOL EnoughRoom = (pObj->GetSize() + m_CurrentSize <= m_Ceiling); 00267 do 00268 { 00269 BOOL ObjectDeleted = DeleteObject(); 00270 00271 EnoughRoom = (pObj->GetSize() + m_CurrentSize <= m_Ceiling); 00272 00273 if(!ObjectDeleted && !EnoughRoom) 00274 return FALSE; // no room and no deleted objects 00275 } 00276 while (!EnoughRoom); 00277 00278 return TRUE; 00279 }
|
|
Remove a key from the hash table Note:.
Definition at line 319 of file objcache.cpp. 00320 { 00321 if( m_ObjectMap.erase( hObj ) ) 00322 return TRUE; 00323 00324 return FALSE; 00325 }
|
|
dynamically change the size (in bytes) of the Cache. Note:
Definition at line 187 of file objcache.cpp. 00188 { 00189 // MYTRACE( _T("ObjectCache::SetMaxCacheSize()\n")); 00190 while (m_CurrentSize > NewCeiling) 00191 { 00192 if(!DeleteObject()) 00193 break; 00194 } 00195 m_Ceiling = NewCeiling; 00196 return TRUE; 00197 }
|
|
Definition at line 137 of file objcache.h. |
|
Definition at line 138 of file objcache.h. |
|
Definition at line 141 of file objcache.h. |
|
Definition at line 139 of file objcache.h. |
|
Definition at line 140 of file objcache.h. |