コード例 #1
0
        /// <summary>
        /// 获取当前计算机的内存状态。
        /// </summary>
        /// <returns>该操作如果无异常,则会返回一个包含内存信息和状态的结构。</returns>
        public static SMemoryStatus GetMemoryStatus()
        {
            SMemoryStatus status = new SMemoryStatus
            {
                Length                         = (uint)Marshal.SizeOf(typeof(SMemoryStatus)),
                MemoryLoad                     = 0,
                TotalPhysicalMemory            = 0,
                AvailablePhysicalMemory        = 0,
                TotalPageFile                  = 0,
                AvailablePageFile              = 0,
                TotalVirtualMemory             = 0,
                AvailableVirtualMemory         = 0,
                AvailableExtendedVirtualMemory = 0
            };

            GlobalMemoryStatusEx(ref status);
            return(status);
        }
コード例 #2
0
 private static extern bool GlobalMemoryStatusEx(ref SMemoryStatus buffer);