View Issue Details

IDProjectCategoryView StatusLast Update
0005111JEDI Code LibraryJclSysInfopublic2010-04-08 19:46
ReporterGeroldAssigned Tooutchy 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product VersionVersion 2.1 
Target VersionFixed in VersionVersion 2.2 
Summary0005111: GetTotalPhysicalMemory returns wrong values
DescriptionOn my systems (XP SP3 - 3 GB and Win 7 - 8 GB) GetTotalPhysicalMemory() returns always 2147483647.

I use the following code to get the real value:

{------------------------------------------------------------------------------}

uses
  { JEDI Windows API }
  JwaWinBase;

{------------------------------------------------------------------------------}

function MyGlobalMemoryStatus(var ABuffer: TMemoryStatusEx): BOOL; stdcall;
type
  TFNGlobalMemoryStatusEx = function(var ABuffer: TMemoryStatusEx): BOOL; stdcall;
const
  FallbackSize = $38; // FieldOffset(TMemoryStatusEx, ullAvailExtendedVirtual)
{$WRITEABLECONST ON}
const
  Initialized: Integer = 0;
  FNMemStatEx: TFNGlobalMemoryStatusEx = nil;
{$WRITEABLECONST OFF}
var
  Status: TMemoryStatus;
begin

  if Initialized = 0 then begin
    FNMemStatEx := TFNGlobalMemoryStatusEx(GetProcAddress(GetModuleHandle(kernel32),'GlobalMemoryStatusEx'));
    InterlockedIncrement(Initialized);
  end;

  if Assigned(FNMemStatEx) then begin
    Result := FNMemStatEx(ABuffer);
  end else begin
    if ABuffer.dwLength < FallbackSize then begin
      SetLastError(ERROR_INVALID_PARAMETER);
      Result := False;
    end else begin
      FillChar(Status, SizeOf(TMemoryStatus), 0);
      GlobalMemoryStatus(Status);
      Result := (Status.dwLength = SizeOf(TMemoryStatus));
      if Result then begin
        FillChar(ABuffer, ABuffer.dwLength, 0);
        ABuffer.dwLength := FallbackSize;
        ABuffer.dwMemoryLoad := Status.dwMemoryLoad;
        with ABuffer, Status do begin
          TULargeInteger(ullTotalPhys).LowPart := dwTotalPhys;
          TULargeInteger(ullAvailPhys).LowPart := dwAvailPhys;
          TULargeInteger(ullTotalPageFile).LowPart := dwTotalPageFile;
          TULargeInteger(ullAvailPageFile).LowPart := dwAvailPageFile;
          TULargeInteger(ullTotalVirtual).LowPart := dwTotalVirtual;
          TULargeInteger(ullAvailVirtual).LowPart := dwAvailVirtual;
        end;
      end;
    end;
  end;

end;

{------------------------------------------------------------------------------}

function GetTotalPhysicalMemory: Int64;
var
  MemStatEx: TMemoryStatusEx;
begin
  FillChar(MemStatEx, SizeOf(MemStatEx), 0);
  MemStatEx.dwLength := SizeOf(MemStatEx);
  if MyGlobalMemoryStatus(MemStatEx) then
    Result := MemStatEx.ullTotalPhys
  else
    Result := 0;
end;

{------------------------------------------------------------------------------}

Would be nice to fix this bug. It was the first function I checked after installing the latest version of JCL and JVCL.

Additional InformationASUS P5QPro + Intel E2180 + 3 GB RAM
Windows XP Home SP3 and all updates
Delphi 6 and all Updates
JVCL 3.39 Complete JCL 2.11-Build 3536
TagsNo tags attached.
Fixed in GIT commit
Fixed in SVN revision3213
IDE versionDelphi 6

Relationships

has duplicate 0005135 resolvedoutchy JEDI VCL Physical-/Virtual-/Pagefile-Memory over 4 GB incorrect result by ComputerInfoEx 

Activities

2010-01-15 13:33

 

JclSysInfo.jpg (118,606 bytes)
JclSysInfo.jpg (118,606 bytes)

outchy

2010-03-22 19:47

administrator   ~0017320

This issue should be fixed in revision 3213 for the JCL.

Issue History

Date Modified Username Field Change
2010-01-15 13:33 Gerold New Issue
2010-01-15 13:33 Gerold File Added: JclSysInfo.jpg
2010-01-15 13:33 Gerold IDE version => Delphi 6
2010-01-25 17:14 Robert Rossmair Relationship added related to 0005135
2010-03-22 19:47 outchy Relationship replaced has duplicate 0005135
2010-03-22 19:47 outchy Note Added: 0017320
2010-03-22 19:47 outchy Assigned To => outchy
2010-03-22 19:47 outchy Status new => feedback
2010-04-08 19:46 outchy Fixed in revision => 3213
2010-04-08 19:46 outchy Status feedback => resolved
2010-04-08 19:46 outchy Fixed in Version => Version 2.2 (Subversion repository/Daily zips)
2010-04-08 19:46 outchy Resolution open => fixed