需要查看当前进程可用的物理内存量 [英] need to see how much physical memory is available to current process

查看:192
本文介绍了需要查看当前进程可用的物理内存量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个内存密集型c#4.0图形程序,必须运行在windows xp上,所以经常是内存不足。什么是估计可用物理内存为我的过程的最佳方式?

I have a memory intensive c# 4.0 graphics program that must run on windows xp, so frequently is running out of memory. What is the best way of estimating the available physical memory for my process? I want to stop allocating buffers when the physical memory drops below 250 MB.

推荐答案

您可以使用perfomance计数器,例如:

You can use a perfomance counter, for example:

private PerformanceCounter memoryCounter =
        new PerformanceCounter("Memory", "Available MBytes");

// ...
float mb = this.memoryCounter.NextValue();
float available = (mb * 1024 * 1024) - Process.GetCurrentProcess().PrivateMemorySize64;
Console.Write("RAM: {0} MB"
  , (1.0 * available / 1024 / 1024).ToString("0.##"));

有关更多信息,请查看此答案: http://stackoverflow.com/a/4680030/284240

Have a look at this answer for more informations: http://stackoverflow.com/a/4680030/284240

这篇关于需要查看当前进程可用的物理内存量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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