什么是使用EmptyWorkingSet的副作用? [英] What are the side effects of using EmptyWorkingSet?

查看:2951
本文介绍了什么是使用EmptyWorkingSet的副作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面的代码以释放内存上的一些正在运行的程序,因为我自己的程序需要大量内存资源,运行速度更快。

I'm using the code below to free up memory on some running programs because my own program needs large memory resources to run faster.

[DllImport("psapi.dll")]
public static extern bool EmptyWorkingSet(IntPtr hProcess);

public FreeMem(string programName){

      EmptyWorkingSet(Process.GetCurrentProcess().Handle);
      foreach(Process process in Process.GetProcesses(programName))
      {
            try
            {
                EmptyWorkingSet(process.Handle);
            }
            catch (Exception)
            {
                ...
            }
      } 
}

这似乎是工作的罚款,我能打倒像资源管理器的某些程序的内存使用量从100,000 KB到2000 KB。这是相当不错的,但有没有在这样做的副作用?
一些商业软件也使用这种类似Yamicsoft Vista中/ XP经理和Firefox优化,仅举几例所以我想,如果这有没有不良副作用或有?

It seems to be working fine, I was able to bring down memory usage of some programs like explorer from 100,000 Kb down to 2,000 Kb. That's pretty good but is there a side effect on doing this? Some commercial software are also using this like Yamicsoft Vista/Xp manager and Firefox Optimizer to name a few so i'm thinking if this has no bad side effects or is there?

推荐答案

我怀疑的副作用将是那些其他程序的性能 - 系统会带来页面换出通过调用 EmptyWorkingSet() 回的时候,过程中需要他们。

I suspect the side-effect will be performance of those other programs - the system will bring the pages swapped out by the call to EmptyWorkingSet() back in when the process needs them.

该系统在如此低的水平搞乱充满了危险:尤其是,浏览器页面错误可能会减慢系统的地步奇怪死锁开始后他们的丑陋的头。最好离开这个到Windows,特别是你没有写其他程序。

Messing with the system at such a low level is fraught with danger: in particular, Explorer page faults may slow the system down to the point where strange deadlocks start to rear their ugly heads. Best to leave this to Windows, in particular for other programs that you didn't write.

您可能会发现它更有效地理解为什么自己的程序需要这么多内存。是否有泄漏的地方,也许?

You may find it more efficient to understand why your own program needs so much memory. Is there a leak somewhere, perhaps?

这篇关于什么是使用EmptyWorkingSet的副作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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