I am using the GlobalMemoryStatusEx
function to retrieve information about memory, but this function doesn't work correctly. It returns 0 for all properties. I don't think this function works in my Windows 7 environment.
[StructLayout(LayoutKind.Sequential)]
internal struct MEMORYSTATUSEX
{
internal uint dwLength;
internal uint dwMemoryLoad;
internal ulong ullTotalPhys;
internal ulong ullAvailPhys;
internal ulong ullTotalPageFile;
internal ulong ullAvailPageFile;
internal ulong ullTotalVirtual;
internal ulong ullAvailVirtual;
internal ulong ullAvailExtendedVirtual;
}
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("Kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
internal static extern bool GlobalMemoryStatusEx(ref MEMORYSTATUSEX lpBuffer);
private void btnGlobalMemoryStatusEX_Click(object sender, EventArgs e)
{
MEMORYSTATUSEX statEX = new MEMORYSTATUSEX();
GlobalMemoryStatusEx(ref statEX);
double d = (double)statEX.ullTotalPhys;
}
Can anybody tell me where I went wrong with wrong code?
These two glibc extensions should give you the available number of pages. We can then just multiply that by the pages size sysconf(_SC_PAGESIZE) to find the total available memory in bytes.
Press Ctrl + Shift + Esc to launch Task Manager. Or, right-click the Taskbar and select Task Manager. Select the Performance tab to see current RAM usage displayed in the Memory box, and total RAM capacity listed under Physical Memory.
The total amount of physical memory on a computer depends on how many sticks of RAM are installed and their storage capacity. For example, if a computer has two 64 MB memory modules installed, it has a total of 128 MB of physical memory.
Physical Memory: The amount of RAM installed. Memory Used: The amount of RAM being used. To the right, you can see where the memory is allocated. App Memory: The amount of memory being used by apps. Wired Memory: Memory required by the system to operate.
I find my mistake from: http://www.pinvoke.net/default.aspx/kernel32/GlobalMemoryStatusEx.html
I Changed
internal static extern bool GlobalMemoryStatusEx(ref MEMORYSTATUSEX lpBuffer);
To
static extern bool GlobalMemoryStatusEx([In, Out] MEMORYSTATUSEX lpBuffer);
and changed
GlobalMemoryStatusEx(ref statEX);
To
GlobalMemoryStatusEx(statEX);
It work correctly. Tanks
How about:
My.Computer.Info.TotalPhysicalMemory
My.Computer.Info.AvailablePhysicalMemory
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With