1

sometime, i can create a 10000x10000 bitmap, sometime i can't

depending on how much available physical RAM is free

I would like to know if there a way to figure out before the process start if there enough memory or not

Fredou
  • 19,848
  • 10
  • 58
  • 113
  • You don't list any particular O/S, but you're probably running on something with virtual memory. Just checking the instantaneous free physical memory doesn't mean much. A substantial amount may be used as cache and available on demand. Additional memory may be made available by outpaging other processes. – HABO Jun 05 '12 at 01:06

1 Answers1

1

You can use this to get the current process:

Process proc = Process.GetCurrentProcess();

And then use this to get the private memory usage:

proc.PrivateMemorySize64;

You could also do this (using System.Diagnostics.PerformaceCounter):

protected PerformanceCounter ramCounter; 
ramCounter = new PerformanceCounter("Memory", "Available MBytes");
var freeRAMInMB = ramCounter.NextValue();

The above would get the the amount of free RAM in MB...

Faraday
  • 2,904
  • 3
  • 23
  • 46