SmallDenseHashMap(size_t expected_max_items_in_table) : HashMap(expected_max_items_in_table, HashMap::hasher(), HashMap::key_equal(), Allocator(&fixed_)) { assert(MIN_BUCKETS(N) >= this->bucket_count()); }
void MemMgr_TrackAllocation (PVOID pData, size_t cb, LPSTR pszExpr, LPSTR pszFile, DWORD dwLine, BOOL fSig) { if (!pData) return; if (!MemMgr_Initialize()) return; EnterCriticalSection (l.pcs); // Ensure our hash table will be large enough to handle the new // MEMCHUNK we're about to assign. // if (l.cBuckets < MIN_BUCKETS(l.cChunks+1)) { // Too small! Rebuild the hash table. // REALLOC (l.aBuckets, l.cBuckets, TARGET_BUCKETS(l.cChunks+1), 1); if (l.aBuckets) { for (size_t ii = 0; ii < l.cBuckets; ++ii) l.aBuckets[ii].iFirst = iINVALID; for (size_t iChunk = 0; iChunk < l.cChunks; ++iChunk) { PMEMCHUNK pChunk; if ((pChunk = (PMEMCHUNK)l.pHeap->GetAt(iChunk)) == NULL) continue; size_t iBucket = HASH(PtrToUlong(pChunk->pData),l.cBuckets); if ((pChunk->iNext = l.aBuckets[iBucket].iFirst) != iINVALID) { PMEMCHUNK pNext; if ((pNext = (PMEMCHUNK)l.pHeap->GetAt(pChunk->iNext)) != NULL) pNext->iPrev = iChunk; } l.aBuckets[iBucket].iFirst = iChunk; pChunk->iPrev = iINVALID; } } } // If space was allocated for a trailing signature, write one // if (fSig) *(DWORD *)( (PBYTE)pData + cb ) = dwSIG_AT_END; // Prepare a MEMCHUNK entry and shove it in our array // size_t iChunk = l.cChunks; size_t iBucket = HASH(PtrToUlong(pData),l.cBuckets); BOOL fLinkIn = TRUE; MEMCHUNK Chunk; Chunk.pData = pData; Chunk.fFreed = FALSE; Chunk.cbData = cb; Chunk.pszExpr = pszExpr; Chunk.pszFile = pszFile; Chunk.fCPP = !fSig; Chunk.dwLine = dwLine; Chunk.dwTick = GetTickCount(); Chunk.dwEndSig = (fSig) ? dwSIG_AT_END : 0; Chunk.fInList = FALSE; Chunk.fTared = FALSE; #ifdef TRACK_FREED // Find the memchunk associated with this pData. That's what our // hash table is for. // for (iChunk = l.aBuckets[iBucket].iFirst; iChunk != iINVALID; ) { PMEMCHUNK pChunk; if ((pChunk = (PMEMCHUNK)l.pHeap->GetAt(iChunk)) != NULL) { if (pChunk->pData == pData) { Chunk.iNext = pChunk->iNext; Chunk.iPrev = pChunk->iPrev; fLinkIn = FALSE; break; } } iChunk = (pChunk) ? pChunk->iNext : iINVALID; } if (iChunk == iINVALID) iChunk = l.cChunks; #endif l.cChunks = max (l.cChunks, 1+iChunk); if (fLinkIn) { if ((Chunk.iNext = l.aBuckets[iBucket].iFirst) != iINVALID) { PMEMCHUNK pNext; if ((pNext = (PMEMCHUNK)l.pHeap->GetAt(Chunk.iNext)) != NULL) pNext->iPrev = iChunk; } l.aBuckets[iBucket].iFirst = iChunk; Chunk.iPrev = iINVALID; } if (IsWindow (l.hManager)) MemMgr_AddToList (&Chunk); l.pHeap->SetAt (iChunk, &Chunk); if (Chunk.fCPP) l.Stats.cAllocCpp ++; else // (!Chunk.fCPP) l.Stats.cAllocDyna ++; if (Chunk.fCPP) l.Stats.cbAllocCpp += Chunk.cbData; else // (!Chunk.fCPP) l.Stats.cbAllocDyna += Chunk.cbData; l.Stats.cAllocTotal ++; l.Stats.cbAllocTotal += Chunk.cbData; LeaveCriticalSection (l.pcs); if (IsWindow (l.hManager)) PostMessage (l.hManager, WM_COMMAND, IDC_REFRESH, 0); }
SmallDenseHashMap() : HashMap(N, typename HashMap::hasher(), typename HashMap::key_equal(), Allocator(&fixed_)) { assert(MIN_BUCKETS(N) >= this->bucket_count()); }