Reputation: 5723
I am creating a program that will allocate a huge amount of data in the RAM. Now, if RAM runs out of space, the program will be put on to virtual memory and paging swap will occur. This is very slow. Is it possible to check for remaining space of RAM? And is it possible to check whether the system is now using virtual memory?
This is on C++ on Windows.
Upvotes: 3
Views: 2939
Reputation: 354
Just having the amount of free ram doesn't mean windows will not page your program. You can try the SetProcessWorkingSetSize api for GetCurrentProcess, but it doesn't provide a guarantee, you can instead use VirtualLock which should guarantee it, but you can get degraded perfomance.
Upvotes: 1
Reputation: 73433
You can use GlobalMemoryStatusEx function to get the amount of free RAM. To get a notification when you are running out of RAM you can use QueryMemoryResourceNotification method.
Upvotes: 5