如何计算私人工作集(内存)? [英] How to calculate private working set (memory)?

查看:295
本文介绍了如何计算私人工作集(内存)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何计算使用C#内存的私人工作集?我感兴趣的产生大致相同的数字作为的TaskMgr.exe

How do I calculate the private working set of memory using C#? I'm interested in produces roughly the same figure as taskmgr.exe.

我使用的过程命名空间,并使用类似 WorkingSet64 PrivateMemorySize64 ,但这些数字的方法/数据关闭的100MB或更多的时间。

I'm using the Process namespace and using methods/data like WorkingSet64 and PrivateMemorySize64, but these figures are off by 100MB or more at times.

推荐答案

这是一种高度可变数目,就不能计算。 Windows内存管理不断交换进出RAM页。从的TaskMgr.exe性能计数器得到它。你可以得到相同数量是这样的:

This is a highly variable number, you cannot calculate it. The Windows memory manager constantly swaps pages in and out of RAM. TaskMgr.exe gets it from a performance counter. You can get the same number like this:

using System;
using System.Diagnostics;

class Program {
    static void Main(string[] args) {
        string prcName = Process.GetCurrentProcess().ProcessName;
        var counter = new PerformanceCounter("Process", "Working Set - Private", prcName);
        Console.WriteLine("{0}K", counter.RawValue / 1024);
        Console.ReadLine();
    }
}

,一定要提防的数量确实没有多大的意义,它会下降,当其他进程开始,争夺RAM。

Do beware that the number really doesn't mean much, it will drop when other processes get started and compete for RAM.

这篇关于如何计算私人工作集(内存)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆