public static HeapInfo[] EnumHeaps(int pid) { using (var handle = Win32.CreateToolhelp32Snapshot(CreateToolhelpSnapshotFlags.SnapHeapList, pid)) { if (handle.DangerousGetHandle() == Win32.InvalidFileHandle) { throw new Win32Exception(Marshal.GetLastWin32Error()); } var heaps = new List <HeapInfo>(8); var hi = new HeapList(); hi.Init(); if (!Win32.Heap32ListFirst(handle, ref hi)) { throw new Win32Exception(Marshal.GetLastWin32Error()); } do { var heapInfo = new HeapInfo(hi, pid); heaps.Add(heapInfo); } while (Win32.Heap32ListNext(handle, ref hi)); return(heaps.ToArray()); } }
internal static extern bool Heap32ListNext(SafeFileHandle hSnapshot, ref HeapList list);
internal HeapInfo(HeapList heap, int pid) { _heap = heap; _pid = pid; }