I have the following code that (correctly) gives me the total installed memory on my computer (note, not the total physical memory, which would be a little less than the installed memory):
using System.Runtime.InteropServices;
[DllImport("kernel32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetPhysicallyInstalledSystemMemory(out long TotalMemoryInKilobytes);
public float getInstalledRAM()
{
long memKb;
GetPhysicallyInstalledSystemMemory(out memKb);
return float.Parse((memKb / 1024 / 1024).ToString());
}
However, when I run it on my test virtual machine, it gives me 1GB less than it should (don't know if the amount matters, but bottom line it's giving me a wrong value). Any possible causes for this?