int CacheCreate(evalCache * pc, unsigned int s) { #if CACHE_STATS pc->cLookup = 0; pc->cHit = 0; pc->nAdds = 0; #endif if (s > 1u << 31) return -1; pc->size = s; /* adjust size to smallest power of 2 GE to s */ while ((s & (s - 1)) != 0) s &= (s - 1); pc->size = (s < pc->size) ? 2 * s : s; pc->hashMask = (pc->size >> 1) - 1; pc->entries = (cacheNode *) malloc((pc->size / 2) * sizeof(*pc->entries)); if (pc->entries == 0) return -1; CacheFlush(pc); return 0; }
/* * CacheDestroy * * Shutdown the cache. */ int CacheDestroy (Cache_t *cache) { CacheFlush( cache ); #if CACHE_DEBUG /* Print cache report */ printf ("Cache Report:\n"); printf ("\tRead Requests: %d\n", cache->ReqRead); printf ("\tWrite Requests: %d\n", cache->ReqWrite); printf ("\tDisk Reads: %d\n", cache->DiskRead); printf ("\tDisk Writes: %d\n", cache->DiskWrite); printf ("\tSpans: %d\n", cache->Span); #endif /* Shutdown the LRU */ LRUDestroy (&cache->LRU); /* I'm lazy, I'll come back to it :P */ return (EOK); }