public DefaultComparer(SortedListViewComparer sortedListComparer) { _sortedListComparer = sortedListComparer; }
public HeapsWindow(int pid, HeapInformation[] heaps) { InitializeComponent(); this.AddEscapeToClose(); this.SetTopMost(); listHeaps.AddShortcuts(); listHeaps.ContextMenu = menuHeap; GenericViewMenu.AddMenuItems(copyMenuItem.MenuItems, listHeaps, null); // Native threads don't work properly on XP. if (OSVersion.IsBelowOrEqual(WindowsVersion.XP)) destroyMenuItem.Visible = false; var comparer = new SortedListViewComparer(listHeaps); listHeaps.ListViewItemSorter = comparer; comparer.CustomSorters.Add(1, (l1, l2) => { HeapInformation heap1 = l1.Tag as HeapInformation; HeapInformation heap2 = l2.Tag as HeapInformation; return heap1.BytesAllocated.CompareTo(heap2.BytesAllocated); }); comparer.CustomSorters.Add(2, (l1, l2) => { HeapInformation heap1 = l1.Tag as HeapInformation; HeapInformation heap2 = l2.Tag as HeapInformation; return heap1.BytesCommitted.CompareTo(heap2.BytesCommitted); }); _pid = pid; IntPtr defaultHeap = IntPtr.Zero; try { using (var phandle = new ProcessHandle( pid, Program.MinProcessQueryRights | Program.MinProcessReadMemoryRights)) defaultHeap = phandle.GetHeap(); } catch (WindowsException) { } long allocatedTotal = 0, committedTotal = 0; int entriesTotal = 0, tagsTotal = 0, pseudoTagsTotal = 0; foreach (HeapInformation heap in heaps) { ListViewItem litem = listHeaps.Items.Add(new ListViewItem( new string[] { Utils.FormatAddress(heap.Address), heap.BytesAllocated.ToString("N0") + " B", heap.BytesCommitted.ToString("N0") + " B", heap.EntryCount.ToString("N0") //heap.TagCount.ToString("N0"), //heap.PseudoTagCount.ToString("N0") })); litem.Tag = heap; // Make the default heap bold. if (heap.Address == defaultHeap) litem.Font = new Font(litem.Font, FontStyle.Bold); // Sum everything up. allocatedTotal += heap.BytesAllocated; committedTotal += heap.BytesCommitted; entriesTotal += heap.EntryCount; tagsTotal += heap.TagCount; pseudoTagsTotal += heap.PseudoTagCount; } // Totals row. listHeaps.Items.Add(new ListViewItem( new string[] { "Totals", allocatedTotal.ToString("N0") + " B", committedTotal.ToString("N0") + " B", entriesTotal.ToString("N0") //tagsTotal.ToString("N0"), //pseudoTagsTotal.ToString("N0") })).Tag = new HeapInformation( IntPtr.Zero, allocatedTotal, committedTotal, tagsTotal, entriesTotal, pseudoTagsTotal ); }