22 #if !defined(_OS_WIN32_) || defined(__MINGW32__) 29 : m_head(-1), m_tail(-1),
30 m_size(1<<logSize), m_count(0), m_freeHashNodes(0), m_freeCacheNodes(0),
124 #define cache_debug_printf printf 127 cache_debug_printf(
"MRU->LRU: ");
131 cache_debug_printf(
"%d=%p ",index,
m_cache[index].obj);
134 cache_debug_printf(
"\n");
136 cache_debug_printf(
"LRU->MRU: ");
140 cache_debug_printf(
"%d=%p ",index,
m_cache[index].obj);
143 cache_debug_printf(
"\n");
148 #define cache_stats_printf printf 177 static bool isPtr64 =
sizeof(
addr)==8;
190 return (
unsigned int)(key & (
m_size-1));
195 uintptr_t
key = (uintptr_t)addr;
202 return (
unsigned int)(key & (
m_size-1));
232 assert(newElement!=-1);
235 if (
m_hash[index].head!=-1)
238 while (
m_hash[index].nextHash!=-1)
252 return &
m_hash[newElement];
262 while (
m_hash[curIndex].obj!=obj)
264 prevIndex = curIndex;
290 obj() : handle(-1) {}
293 obj *objs =
new obj[100];
297 int objId=(i%3)+(i>>2)*4;
298 printf(
"------- use(%d=%p)--------\n",objId,&objs[objId]);
303 if (objs[objId].handle==-1)
305 objs[objId].handle = c.
add(&objs[objId],(
void**)&victim);
306 if (victim) victim->handle=-1;
310 c.
use(objs[objId].handle);
312 printf(
"i=%d objId=%d using %p victim=%p\n",i,objId,&objs[objId],victim);
316 if (objs[i].handle!=-1)
318 printf(
"------ del objId=%d handle=%d ------\n",i,objs[i].handle);
319 c.
del(objs[i].handle);
#define cache_stats_printf
unsigned int hash(void *addr)
void hashRemove(void *obj)
int add(void *obj, void **victim)
void moveToFront(int index)
unsigned long long uint64
HashNode * hashInsert(void *obj)
ObjCache(unsigned int logSize)
constexpr std::enable_if_t< are_cv_compatible< TO, FROM >::value, std::add_pointer_t< std::remove_pointer_t< TO > > > addr(FROM &from)
HashNode * hashFind(void *obj)