简体   繁体   中英

c# - How to get the amount of memory available for my application

I found out that I can read the available physical memory by the ComputerInfo.TotalPhysicalMemory Property. http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.devices.computerinfo.totalphysicalmemory.aspx

But is there any way to find out the memory that is actually available for my application. So, that for example, I can react if I'm running out of memory.

Is that possible? Or is that just bad practice.

Thanks in Advance

If you read the Eric Lippert article you'll hit this important paragraph:

An “out of memory” error almost never happens because there's not enough storage available; as we've seen, storage is disk space, and disks are huge these days. Rather, an “out of memory” error happens because the process is unable to find a large enough section of contiguous unused pages in its virtual address space to do the requested mapping.

There is no way to know if there are contiguous unused pages available.

The best thing you can do is die gracefully when you have an "Out of Memory" exception.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM