How can I get the total physical memory in C#?

前端 未结 5 879
执笔经年
执笔经年 2020-12-15 23:56

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

5条回答
  •  悲哀的现实
    2020-12-16 00:39

    You forgot to set statEX.dwLength before calling GlobalMemoryStatusEx.

    MEMORYSTATUSEX statEX = new MEMORYSTATUSEX();
    statEX.dwLength = (uint)Marshal.SizeOf(typeof(MEMORYSTATUSEX));
    GlobalMemoryStatusEx(ref statEX);
    

提交回复
热议问题