Karl
Karl

Reputation: 5723

check for remaining space in RAM on Windows?

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

Answers (2)

Dan
Dan

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

Naveen
Naveen

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

Related Questions