我需要使用Delphi 2007获取系统的总物理内存.在4GB或更大的系统上使用GlobalMemoryStatus似乎给了我错误.在Delphi 2007中,GlobalMemoryStatusEx不存在,所以我手动将函数调用添加到我的程序中.它正确
任何想法我可能做错了什么? GlobalMemoryStatusEx是否适用于较旧的操作系统?
type DWORDLONG = UInt64; PMemoryStatusEx = ^TMemoryStatusEx; TMemoryStatusEx = packed record dwLength: DWORD; dwMemoryLoad: DWORD; ullTotalPhys: DWORDLONG; ullAvailPhys: DWORDLONG; ullTotalPageFile: DWORDLONG; ullAvailPageFile: DWORDLONG; ullTotalVirtual: DWORDLONG; ullAvailVirtual: DWORDLONG; ullAvailExtendedVirtual: DWORDLONG; end; function GlobalMemoryStatusEx(var lpBuffer: TMemoryStatusEx): BOOL; stdcall; external kernel32; function getmemorysize:word; var memory: TMemoryStatusEx; begin FillChar(memory, SizeOf(memory), 0); memory.dwLength := SizeOf(memory); GlobalMemoryStatusEx(memory); result:=memory.ullTotalPhys div (1024*1024); end;这是可以预料的,你没有做错任何事. Windows不会在32位操作系统上报告4GB内存.这是来自MSDN blog article的引用,名为“3GB-not-4GB RAM问题”:
Due to an architectural decision made long ago, if you have 4GB of
physical RAM installed, Windows is only able to report a portion of
the physical 4GB of RAM (ranges from ~2.75GB to 3.5GB depending on the
devices installed, motherboard’s chipset & BIOS).
GlobaMemoryStatusEx应该可以从Windows 2000开始运行(以后的MSDN文档不包括Win2K,但早期的文件有.)