简体   繁体   English

如何强制Windows向所有应用程序发送'LOW_MEMORY'信号?

[英]How to force Windows to send 'LOW_MEMORY' signal to all applications?

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). 我正在研究一些“免费RAM”工具,它必须强制Windows向所有应用程序发送'LOW_MEMORY'信号(要求所有应用程序释放它们未使用的数据,SQL服务器和文件缓存被清除,这样你最终会得到很多额外的免费空间)。

What will be best approach to do it in C++? 在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? 也许在WinAPI或其他地方有任何c ++ Windows本机函数?

ps 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): ps该工具的概念来自(我知道更好的方法是......购买一些RAM,但我现在必须编写这样的工具):

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

Another possibility could be to iterate thru the active process list, and ask each one to trim it's working set, via SetProcessWorkingSetSize ( hProcess, (SIZE_T)-1, (SIZE_T)-1), as described here on MSDN , potentially skipping applications if your intent is to attempt to improve performance of some particular application (benchmarking is absolutely your friend here). 另一种可能是通过活动进程列表进行迭代,并通过SetProcessWorkingSetSize (hProcess,(SIZE_T)-1,(SIZE_T)-1)要求每个人修剪它的工作集,如MSDN中所述 ,可能会跳过应用程序,如果您的意图是尝试提高某些特定应用程序的性能(基准测试绝对是您的朋友)。

This causes the OS to flush virtual pages to disk, freeing up physical memory for other applications. 这会导致操作系统将虚拟页面刷新到磁盘,从而为其他应用程序释放物理内存。 I'm not sure if this will cause, eg, SQL Server to relax it's memory demands, but it is certainly worth a try. 我不确定这是否会导致,例如,SQL Server放松它的内存需求,但它肯定值得一试。

There are a few links which may be of use to you at MSDN: 在MSDN上有一些可能对您有用的链接:

Hopefully these can give you a start. 希望这些可以给你一个开始。 The other way you could free up ram is to signal windows to page every processes RAM allocation to swap file, which will free physical RAM up. 你可以释放RAM的另一种方法是发信号通知窗口将每个进程的RAM分配到交换文件,这将释放物理RAM。 Then as the user uses a particular application it will be moved back to physical ram by the OS, that way the management is still handled for the most part by the OS. 然后,当用户使用特定应用程序时,它将被OS移回物理RAM,这样管理仍然大部分由OS处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将键盘事件发送到Windows中的所有类型的应用程序? - How to send keyboard events to all kind of applications in windows? Windows CE中的内存不足通知 - Low memory notifications in Windows CE 如何从子进程向所有进程发送信号? - How to send a signal to all process from child process? 如何枚举/列出 Windows XP 中所有已安装的应用程序? - How can I enumerate/list all installed applications in Windows XP? 如何从Windows防火墙获取例外列表中的所有应用程序? - How to get all applications in the exception list from Windows firewall? 如何使用WindowsFormApplication按钮在两个Windows应用程序之间切换(强制将它们置于顶部)? - How can I use a WindowsFormApplication button to toggle between two Windows applications (force them to top)? 如何强制使用库的应用程序在 windows 上包含特定的应用程序清单设置 - How to force applications using a library to include specific application manifest settings on windows Windows上Qt应用程序的内存泄漏检测工具 - Memory leak detection tool for qt applications on windows 如何从代表发送信号 - How to send a signal from delegate 如何在函数中释放低堆memory? - How to free low heap memory in a function?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM