How do I determine how much more memory my process can allocate

The most useful info so far seems to be use...

GlobalMemoryStatusEx() to get



and ...

GetProcessMemoryInfo() to get


I think ullTotalVirtual is the maximum amount of memory my process can allocate. Is that right And ullAvailVirtual is the amount I have left, right But if I run my app in a loop that allocates memory, it will crash before ullAvailVirtual gets below 300MB.

Another problem is that ullAvailVirtual does not decrease steadily during this time. It seems to go down in chunks. And sometimes it even goes up.

PageFileUsage, on the otherhand, seems to correspond quite well with what I would expect. It goes up by the same amount after each allocation. But, similar to ullAvailVirtual, when my app crashes, PageFileUsage is at least 300MB less than ullTotalVirtual.

Yet another problem is that my app will crash with varying amounts of memory remaining. Sometimes its 300MB sometimes it's 600MB.

So, is there any reliable way to know how much more memory I can allocate

Re: Visual C++ General Remaining process memory

Ryan Lamansky

When you get close to the limits, it becomes increasingly difficult to find a large enough block of free address space to allocate your object. You might have a lot of total space left, but in tiny chunks that are too small for your object, thus hitting memory errors earlier than you might expect. .NET managed applications are somewhat less suceptible to this because of the compacting garbage collector Microsoft uses.

I'm not aware of a perfect way to check remaining memory other than to allocate the object and handle the error if it fails. If you're repeatedly encountering this problem, consider redesigning your memory management strategy or switching to a 64-bit environment, or both.

-Ryan / kardax

Re: Visual C++ General Remaining process memory


Thanks for the info. I don't really need more memory for my application to function. I just need to give the user a warning when they are getting close to the limit. Is there a reliable way to know we are close to the limit From what you say it seems like "close to the limit" is a function of ullAvailVirtual and the amount of memory fragmentation. Are there other significant factors Is there any way to get any info about how fragmented memory is

Re: Visual C++ General Remaining process memory

Damien Watkins - MSFT


Re: Remaining process memory

Such questions are outside the scope of this forum - for the scope of the VC General forum please look at: PostID=19445&SiteID=1

The more appropriate place for your question is probably one of the Win32 newsgroups: url=/MSDN-FILES/028/201/015/topic.xml