This gets all memory used by a specific process Assume that dwProcessID is an ID of a process :)
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPHEAPLIST | TH32CS_SNAPMODULE, dwProcessID); DWORD dwSize = 0; // Will contain the total memory usage when we're done!
MODULEENTRY32 module; module.dwSize = sizeof(module);
if (Module32First(hSnapshot, &module)) { do { dwSize += module.modBaseSize; }while (Module32Next(hSnapshot, &module)); }
HEAPLIST32 heap; heap.dwSize = sizeof(heap);
// Get all memory used by the heap if (Heap32ListFirst(hSnapshot, &heap)) { do { HEAPENTRY32 heapentry; heapentry.dwSize = sizeof(heapentry); if (Heap32First(&heapentry,heap.th32ProcessID,heap.th32HeapID)) { do { if (heapentry.dwFlags != LF32_FREE) // If the block is currently used dwSize += heapentry.dwBlockSize; }while (Heap32Next(&heapentry)); } }while (Heap32ListNext(hSnapshot,&heap)); } CloseHandle(hSnapshot);
|