Question

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

Was it helpful?

Solution

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).

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, e.g., SQL Server to relax it's memory demands, but it is certainly worth a try.

OTHER TIPS

There are a few links which may be of use to you at 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. 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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top