[英]Strange value for available physical memory
I use a code library that contains a function to calculate the amount of memory avaliable. 我使用的代码库包含一个函数来计算可用的内存量。
For hosted PC's (hosted by Windows 2008 R2 x64) I sometimes see the free amount calculated in a funny way. 对于托管的PC(由Windows 2008 R2 x64托管),有时会看到以有趣的方式计算的免费金额。
It gets reported as 它被报告为
physical memory : 1400/1400 MB (free/total)
物理内存:1400/1400 MB(可用/总计)
Which cant really be true, since several applications are running. 由于几个应用程序正在运行,因此不能真正做到这一点。 How can that happen?
怎么会这样
My interest here is whether this phenomenon points to a memory problem. 我的兴趣是这种现象是否指向内存问题。 Sometimes my application runs out of memory when hosted on a VM with limited memory like 1400 MB.
有时,当我的应用程序托管在内存有限(例如1400 MB)的VM上时,我的应用程序会用光内存。 So when I see a bug report with the available meory wrongly reported as 1400 MB could it be that it really is zero?
因此,当我看到一个错误报告,其中可用内存错误地报告为1400 MB时,是否真的为零?
Here is the code 这是代码
function GetMemoryStatus : UnicodeString;
type
TMemoryStatusEx = record
dwLength : dword;
dwMemoryLoad : dword;
ullTotalPhys : int64;
ullAvailPhys : int64;
ullTotalPageFile : int64;
ullAvailPageFile : int64;
ullTotalVirtual : int64;
ullAvailVirtual : int64;
ullAvailExtendedVirtual : int64;
end;
var gmse : function (var mse: TMemoryStatusEx) : bool; stdcall;
ms : TMemoryStatus;
mse : TMemoryStatusEx;
begin
gmse := GetProcAddress(GetModuleHandle(kernel32), 'GlobalMemoryStatusEx');
if @gmse <> nil then begin
mse.dwLength := sizeOf(mse);
gmse(mse);
end else begin
ms.dwLength := sizeOf(ms);
GlobalMemoryStatus(ms);
mse.ullAvailPhys := ms.dwAvailPhys;
mse.ullTotalPhys := ms.dwTotalPhys;
end;
result := IntToStrExW((mse.ullAvailPhys + $80000) div $100000) + '/' +
IntToStrExW((mse.ullTotalPhys + $80000) div $100000) + ' MB (free/total)';
end;
Thanks! 谢谢! Jacob
雅各布
I can't reproduce your problem. 我无法重现您的问题。 The only difference is some changes to the calculations you're doing in the
Result
line, because I don't have MadExcept on the system I'm on right now (will rectify that soon). 唯一的区别是对
Result
行中所做的计算进行了一些更改,因为我现在使用的系统上没有MadExcept(将尽快解决)。 Here's the code I used: 这是我使用的代码:
type
TMemoryStatusEx = record
dwLength : dword;
dwMemoryLoad : dword;
ullTotalPhys : int64;
ullAvailPhys : int64;
ullTotalPageFile : int64;
ullAvailPageFile : int64;
ullTotalVirtual : int64;
ullAvailVirtual : int64;
ullAvailExtendedVirtual : int64;
end;
type
TGlobalMemoryStatusEx = function (var mse: TMemoryStatusEx) : bool; stdcall;
function GetMemoryStatus : string;
var
GlobalMemoryStatusEX: TGlobalMemoryStatusEx;
MemStatEx : TMemoryStatusEx;
begin
GlobalMemoryStatusEx := GetProcAddress(GetModuleHandle(kernel32),
'GlobalMemoryStatusEx');
if @GlobalMemoryStatusEx <> nil then
begin
MemStatEx.dwLength := sizeOf(MemStatEx);
GlobalMemoryStatusEx(MemStatEx);
Result := Format('%d / %d KB (free/total), ',
[MemStatEx.ullAvailPhys div 1024,
MemStatEx.ullTotalPhys div 1024 ]);
end;
end;
procedure TForm3.FormShow(Sender: TObject);
begin
Label1.Caption := GetMemoryStatus;
end;
Here's the output of the app (with Task Manager's Physical Memory pane beneath it for comparison), running in a Windows XP Mode virtual machine on Windows 7. The VM was set up with 1GB of RAM, and has this test app, Task Manager, and a single Windows Explorer instance running. 这是应用程序的输出(下面带有“任务管理器”的“物理内存”窗格以进行比较),该输出在Windows 7上的Windows XP Mode虚拟机中运行。VM设置了1GB的RAM,并具有此测试应用程序“任务管理器”,并运行一个Windows资源管理器实例。 (The app was written in D2007 on Win 7 64-bit, and then copied/pasted into the VM and started by double-clicking in Explorer.)
(该应用程序是用D2007在Win 7 64位上编写的,然后将其复制/粘贴到VM中,并通过双击资源管理器来启动。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.