Reputation: 20620
I have a MFC application written in VC6. I would like to temporarily allocate possible maximum memory for certain operation. In order to do that, I need to find how much memory I can allocate at current state of the program. Is there any useful function or code to do this?
Of course, I can try to allocate memories multiple times in descending order and see if it is allocated or not. But is there better way to do this?
Upvotes: 1
Views: 660
Reputation: 5537
To get the maximum amount of memory that can be allocated, I would actually allocate memory in ascending order, using realloc to double the allocated memory each time until it fails. However, there's no guarantee that the allocated memory is actually in physical RAM, which may matter depending on what you plan on using this memory for. Refer to this article about when and why memory allocation may fail.
Upvotes: 1