日期:2014-05-18 浏览次数:21167 次
// 定义结构和方法 [StructLayout(LayoutKind.Sequential)] private struct _MEMORYSTATUS { public uint dwLength; public uint dwMemoryLoad; public uint dwTotalPhys; public uint dwAvailPhys; public uint dwTotalPageFile; public uint dwAvailPageFile; public uint dwTotalVirtual; public uint dwAvailVirtual; } [DllImport("Kernel32.dll", CallingConvention = CallingConvention.StdCall)] private static extern void GlobalMemoryStatus(ref _MEMORYSTATUS lpBuffer); // 调用代码 _MEMORYSTATUS ms = new _MEMORYSTATUS(); GlobalMemoryStatus(ref ms); uint 总物理内存 = ms.dwTotalPhys; uint 可用物理内存 = ms.dwAvailPhys;