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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With