Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3306074
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:14:43+00:00 2026-05-17T21:14:43+00:00

I am using DelphiIXE. I learned that GlobalMemoryStatus may return wrong results on 64

  • 0

I am using DelphiIXE.

I learned that GlobalMemoryStatus may return wrong results on 64 computers with more than
4G RAM, so GlobalMemoryStatusex should be used.

But, on the other hand, if I use GlobalMemoryStatusex on 32 computer, the results are wrong on as well (returned numbers are 0 or huge).

Of course I can prepare two programs: one for 64 and one for 32 computers,
and use the right memory status, but is there a way to use the same
call or recognize that computer is 64?
And do something like:

if comp64 then  begin
   GlobalMemoryStatusex 
   ....
end
else begin
   GlobalMemoryStatus 
   ....
end;

This is the code I’m using now:

var 
  MS1: TMemoryStatusex;
begin
  GlobalMemoryStatusex(MS1);
  showmessage('KiloBytes of physical memory: '+FormatFloat('#,###" KB"', MS1.ullTotalPhys / 1024)+chr(10)+
              'Percent of memory in use: '+Format('%d%%', [MS1.dwMemoryLoad])+chr(10)+
              'KiloBytes of free physical memory: '+FormatFloat('#,###" KB"', MS1.ullAvailPhys /1024)+chr(10)+chr(10)+
              'KiloBytes of paging file space: '+FormatFloat('#,###" KB"', MS1.ullTotalPageFile / 1024)+chr(10)+
              'KiloBytes of free paging file space: '+FormatFloat('#,###" KB"', MS1.ullAvailPageFile / 1024)+chr(10)+chr(10)+
              'KiloBytes of virtual address space: '+FormatFloat('#,###" KB"', MS1.ullTotalVirtual / 1024)+chr(10)+
              'KiloBytes of free virtual address space: '+FormatFloat('#,###" KB"', MS1.ullAvailVirtual / 1024) );

Thanks in advance.


TOndrej, here is the code:

var MS1:TMemoryStatusex;
    GlobalMemoryStatusex(MS1);
    showmessage('KiloBytes of physical memory: '+FormatFloat('#,###" KB"', MS1.ullTotalPhys / 1024)+chr(10)+
                 'Percent of memory in use: '+Format('%d%%', [MS1.dwMemoryLoad])+chr(10)+
                 'KiloBytes of free physical memory: '+FormatFloat('#,###" KB"', MS1.ullAvailPhys /1024)+chr(10)+chr(10)+
                 'KiloBytes of paging file space: '+FormatFloat('#,###" KB"', MS1.ullTotalPageFile / 1024)+chr(10)+
                 'KiloBytes of free paging file space: '+FormatFloat('#,###" KB"', MS1.ullAvailPageFile / 1024)+chr(10)+chr(10)+
                 'KiloBytes of virtual address space: '+FormatFloat('#,###" KB"', MS1.ullTotalVirtual / 1024)+chr(10)+
                 'KiloBytes of free virtual address space: '+FormatFloat('#,###" KB"', MS1.ullAvailVirtual / 1024) );
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T21:14:43+00:00Added an answer on May 17, 2026 at 9:14 pm

    It seems you are not initializing the structure and you’re not checking the return code. Here’s a compilable project which should work:

    program Project1;
    
    {$APPTYPE CONSOLE}
    
    uses
      Windows,
      Classes,
      SysUtils;
    
    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;
    
    procedure Main;
    var
      MemStatus: TMemoryStatusEx;
    begin
      // initialize the structure
      FillChar(MemStatus, SizeOf(MemStatus), 0);
      MemStatus.dwLength := SizeOf(MemStatus);
      // check return code for errors
      Win32Check(GlobalMemoryStatusEx(MemStatus));
    
      Writeln(Format('dwLength: %d', [MemStatus.dwLength]));
      Writeln(Format('dwMemoryLoad: %d', [MemStatus.dwMemoryLoad]));
      Writeln(Format('ullTotalPhys: %d', [MemStatus.ullTotalPhys]));
      Writeln(Format('ullAvailPhys: %d', [MemStatus.ullAvailPhys]));
      Writeln(Format('ullTotalPageFile: %d', [MemStatus.ullTotalPageFile]));
      Writeln(Format('ullAvailPageFile: %d', [MemStatus.ullAvailPageFile]));
      Writeln(Format('ullTotalVirtual: %d', [MemStatus.ullTotalVirtual]));
      Writeln(Format('ullAvailVirtual: %d', [MemStatus.ullAvailVirtual]));
      Writeln(Format('ullAvailExtendedVirtual: %d', [MemStatus.ullAvailExtendedVirtual]));
    end;
    
    begin
      try
        Main;
      except
        on E: Exception do
        begin
          ExitCode := 1;
          Writeln(Format('[%s] %s', [E.ClassName, E.Message]));
        end;
      end;
    end.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using ASP.NET MVC there are situations (such as form submission) that may require a
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
Using C#, I need a class called User that has a username, password, active
Using online interfaces to a version control system is a nice way to have
Using PyObjC , you can use Python to write Cocoa applications for OS X.
Using C# .NET 3.5 and WCF, I'm trying to write out some of the
Using C# and System.Data.SqlClient, is there a way to retrieve a list of parameters
Using VS2008, C#, .Net 2 and Winforms how can I make a regular Button
Using JDeveloper , I started developing a set of web pages for a project
Using preview 4 of ASP.NET MVC Code like: <%= Html.CheckBox( myCheckBox, Click Here, True,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.