6

I'm working on some "free RAM" tool that has to force windows to send 'LOW_MEMORY' signal to all applications (that asks all application to free their unused data, SQL server and file caches get cleared so you'll end up with lots of extra free space).

What will be best approach to do it in C++? The most "natural" solution for me would be to allocate a big amount of memory, but is it a "good" and "stable" way? Maybe there is any c++ Windows native function for it in WinAPI or somewhere else?

p.s. The concept of that tool came from (and I know that better way is to... buy some RAM, but I have to write such tool now):

https://superuser.com/questions/214526/how-does-a-free-up-ram-utility-free-up-ram

4

2 回答 2

2

另一种可能性可能是遍历活动进程列表,并要求每个人通过SetProcessWorkingSetSize ( hProcess, (SIZE_T)-1, (SIZE_T)-1) 修剪其工作集,如MSDN 上所述,如果可能会跳过应用程序您的意图是尝试提高某些特定应用程序的性能(基准测试绝对是您的朋友)。

这会导致操作系统将虚拟页面刷新到磁盘,从而为其他应用程序释放物理内存。我不确定这是否会导致,例如,SQL Server 放宽它的内存需求,但它当然值得一试。

于 2013-11-15T18:48:36.730 回答
0

MSDN 上有一些链接可能对您有用:

希望这些能给你一个开始。释放内存的另一种方法是向窗口发出信号,将每个进程的内存分配给交换文件,这将释放物理内存。然后当用户使用特定的应用程序时,它将被操作系统移回物理内存,这样管理仍然大部分由操作系统处理。

于 2013-11-12T16:50:20.987 回答