【发布时间】:2016-06-07 15:40:15
【问题描述】:
我知道 Process 类有许多与内存相关的属性,例如 (Private)WorkingSet(64)、PrivateMemorySize64(字节单位)……我试图获取它们的值并除以 (1024*1024) 以获得 MB 数其中。似乎它们都没有像任务管理器内存列那样的值。是否有具有 TM 价值的属性?
【问题讨论】:
标签: c# memory process taskmanager
我知道 Process 类有许多与内存相关的属性,例如 (Private)WorkingSet(64)、PrivateMemorySize64(字节单位)……我试图获取它们的值并除以 (1024*1024) 以获得 MB 数其中。似乎它们都没有像任务管理器内存列那样的值。是否有具有 TM 价值的属性?
【问题讨论】:
标签: c# memory process taskmanager
不,进程上没有可以从中获取任务管理器私有工作集的属性,但是...
您可以从the original answer there 的性能计数器中检索相同的值:
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();
}
}
您可能不知道 Process 中可用的值并不代表同一事物。 Private Working Set 仅与由 PrivateMemorySize64 测量的内存子集相关。见答案there。
事实上,这真的取决于你想要达到的目标。
作为旁注,Process 上的所有“非 64”内存相关属性都已过时。您还应该阅读Process documentation。
供参考私人工作集与任务管理器或Process Explorer的同一列中显示的内容相关。
您可以参考Windows documentation 或related question 以了解每个任务管理器列的含义。
【讨论】: