Hi,
I have a tool that depending on input may need huge amounts of memory. The problem is that the system may run out of memory. The default configuration of Windows starts swapping at this point, and when that's not enough, the default configuration causes a dynamic resize of the swap file, which effectively freezes the entire system. On 32 bit Windows, the address space eventually runs out and allocations fail, causing my app to receive a System.OutOfMemoryException, but that may not happen on 64-bit Windows. At least not in acceptable time. The result is that my app can cause the system to freeze for an unknown amount of time where the only out is a hard reset. I personally think this is a bad and dangerous behavior of Windows, at least for a default, but it is what it is so I need a workaround. It's not realistic to reduce memory usage or switch to some file based solution, manual or memory mapped files.
What I want to do at this point is to warn the user when the app is about to use large amounts of memory and ask for confirmation before continuing. To do this, I need to figure out how much memory is "safe" to use at the moment. If the user has 4GB is his system, then perhaps I should only use 1.5GB before warning. If the user has 32GB, I could likely use 20+ without issues. I should probably have some level of respect for other applications running.
How would you do this? What system and application properties should I be looking at? Working set, virtual memory usage, commit size, etc?