/// <summary> /// 获取内存占用率 /// </summary> /// <returns></returns> public static uint GetMenoryLoad() { MEMORY_INFO memInfo = new MEMORY_INFO(); MEMORYSTATUSEX memEx = new MEMORYSTATUSEX(); memEx.dwLength = (uint)Marshal.SizeOf(typeof(MEMORYSTATUSEX)); GlobalMemoryStatusEx(ref memEx); GlobalMemoryStatus(ref memInfo); return(memInfo.dwMemoryLoad); }
/// <summary> /// 获取内存信息 /// </summary> /// <returns></returns> public static MemoryInfo GetMemoryInfo() { MEMORY_INFO memInfo = new MEMORY_INFO(); MEMORYSTATUSEX memEx = new MEMORYSTATUSEX(); memEx.dwLength = (uint)Marshal.SizeOf(typeof(MEMORYSTATUSEX)); GlobalMemoryStatusEx(ref memEx); GlobalMemoryStatus(ref memInfo); MemoryInfo memoryInfo = new MemoryInfo(); memoryInfo.MemoryLoad = memInfo.dwMemoryLoad; memoryInfo.AvailPhys = memInfo.dwAvailPhys; memoryInfo.TotalPhys = memInfo.dwTotalPhys; return(memoryInfo); }
public static extern void GlobalMemoryStatus(ref MEMORY_INFO meminfo);