Beispiel #1
0
        /// <summary>
        /// 获取内存信息
        /// </summary>
        /// <returns></returns>
        public OsMemoryInfo GetInfo()
        {
            OsMemoryInfo result = new OsMemoryInfo();

            if (Environment.Is64BitProcess)
            {
                //调用GlobalMemoryStatus函数获取内存的相关信息
                MEMORY_INFO_64bit MemInfo_64bit = new MEMORY_INFO_64bit();
                GlobalMemoryStatus(ref MemInfo_64bit);

                //赋值结果
                result.dwAvailPageFile = Convert.ToUInt64(MemInfo_64bit.dwAvailPageFile);
                result.dwAvailPhys = Convert.ToUInt64(MemInfo_64bit.dwAvailPhys);
                result.dwAvailVirtual = Convert.ToUInt64(MemInfo_64bit.dwAvailVirtual);
                result.dwLength = Convert.ToUInt64(MemInfo_64bit.dwLength);
                result.dwMemoryLoad = Convert.ToUInt64(MemInfo_64bit.dwMemoryLoad);
                result.dwTotalPageFile = Convert.ToUInt64(MemInfo_64bit.dwTotalPageFile);
                result.dwTotalPhys = Convert.ToUInt64(MemInfo_64bit.dwTotalPhys);
                result.dwTotalVirtual = Convert.ToUInt64(MemInfo_64bit.dwTotalVirtual);
            }
            else
            {
                //调用GlobalMemoryStatus函数获取内存的相关信息
                MEMORY_INFO_32bit MemInfo_32bit = new MEMORY_INFO_32bit();
                GlobalMemoryStatus(ref MemInfo_32bit);

                //赋值结果
                result.dwAvailPageFile = Convert.ToUInt32(MemInfo_32bit.dwAvailPageFile);
                result.dwAvailPhys = Convert.ToUInt32(MemInfo_32bit.dwAvailPhys);
                result.dwAvailVirtual = Convert.ToUInt32(MemInfo_32bit.dwAvailVirtual);
                result.dwLength = Convert.ToUInt32(MemInfo_32bit.dwLength);
                result.dwMemoryLoad = Convert.ToUInt32(MemInfo_32bit.dwMemoryLoad);
                result.dwTotalPageFile = Convert.ToUInt32(MemInfo_32bit.dwTotalPageFile);
                result.dwTotalPhys = Convert.ToUInt32(MemInfo_32bit.dwTotalPhys);
                result.dwTotalVirtual = Convert.ToUInt32(MemInfo_32bit.dwTotalVirtual);
            }

            return result;
        }
Beispiel #2
0
 private static extern void GlobalMemoryStatus(ref MEMORY_INFO_64bit meminfo);