当前位置: 首页>>代码示例>>C#>>正文


C# ProcessHandle.GetHeap方法代码示例

本文整理汇总了C#中ProcessHandle.GetHeap方法的典型用法代码示例。如果您正苦于以下问题:C# ProcessHandle.GetHeap方法的具体用法?C# ProcessHandle.GetHeap怎么用?C# ProcessHandle.GetHeap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ProcessHandle的用法示例。


在下文中一共展示了ProcessHandle.GetHeap方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HeapsWindow

        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
                    );
        }
开发者ID:john-peterson,项目名称:processhacker,代码行数:89,代码来源:HeapsWindow.cs


注:本文中的ProcessHandle.GetHeap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。