[Mono-dev] New performance counter in Mono to report physical memory size in the machine

Marek Habersack grendel at twistedcode.net
Fri Apr 16 13:39:47 EDT 2010


Hey everybody,

	This is just to let you know that Mono in trunk has a new performance counter which returns
the amount of physical RAM in the machine. The need to add such a counter arose from the fact that
there's no means in .NET to get this piece of information. Also, different operating system have
different ways of obtaining the information. Here's the excerpt of code which will get you the
information on Mono/trunk (and 2.8+ when it's released):

--- CUT ---
using System;
using System.Diagnostics;

class app
{
   static void Main ()
   {
       var pc = new PerformanceCounter ("Mono Memory", "Total Physical Memory");
       Console.WriteLine ("Physical RAM (bytes): {0}", pc.RawValue);
   }
}
--- CUT ---

	Code, as committed, works on Linux, {Open,Free,Net}BSD, Solaris, MacOS/X and Windows. If
your operating system reports invalid values (or reports 128MB even though you have 1TB of RAM)
please either file a bug or, better yet, provide a patch which adds support for your OS.
	Hope somebody finds that useful,

marek


More information about the Mono-devel-list mailing list