Get available memory for a program


Is there an easy way to retrieve the available RAM memory on a pc, just like the Windows NT Task Manager shows.

I start some processes in my progam that take a lot of memory, so I want to check at startup whether there's enough free RAM memory available on the machine for my program to run.

Who is Participating?
gemartiConnect With a Mentor Commented:
Which value do you want?

Take your pick


unit Unit1;


  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,

  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Edit5: TEdit;
    Edit6: TEdit;
    Edit7: TEdit;
    Edit8: TEdit;
    procedure Button1Click(Sender: TObject);
    { Private declarations }
    { Public declarations }

  Form1: TForm1;


{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
GlobalMemoryInfo: TMemoryStatus; // holds the global memory status information
   {set the size of the structure before the call}
  GlobalMemoryInfo.dwLength := SizeOf(GlobalMemoryInfo);

  {retrieve the global memory status...}

    {and display the information}
  Edit1.Text := IntToStr(GlobalMemoryInfo.dwLength)+' bytes';
  Edit2.Text := IntToStr(GlobalMemoryInfo.dwMemoryLoad)+' %';
  Edit3.Text := IntToStr(GlobalMemoryInfo.dwTotalPhys)+' bytes';
  Edit4.Text := IntToStr(GlobalMemoryInfo.dwAvailPhys)+ ' bytes';
  Edit5.Text := IntToStr(GlobalMemoryInfo.dwTotalPageFile)+ ' bytes';
  Edit6.Text := IntToStr(GlobalMemoryInfo.dwAvailPageFile)+ ' bytes';;
  Edit7.Text := IntToStr(GlobalMemoryInfo.dwTotalVirtual)+ ' bytes';
  Edit8.Text := IntToStr(GlobalMemoryInfo.dwAvailVirtual)+' bytes';


try this:

procedure TForm1.Button1Click(Sender: TObject);
 PMemStat: ^TMemoryStatus;
 label1.Caption := Format ('Physical Memory Available to Windows: %10.0n KB', [pMemstat.dwAvailVirtual / 1024]);

About pMemstat.dw... from Help:


Indicates the size of the structure. The calling process should set this member prior to calling GlobalMemoryStatus.


Specifies a number between 0 and 100 that gives a general idea of current memory utilization, in which 0 indicates no memory use and 100 indicates full memory use.


Indicates the total number of bytes of physical memory.


Indicates the number of bytes of physical memory available.


Indicates the total number of bytes that can be stored in the paging file. Note that this number does not represent the actual physical size of the paging file on disk.


Indicates the number of bytes available in the paging file.


Indicates the total number of bytes that can be described in the user mode portion of the virtual address space of the calling process.


Indicates the number of bytes of unreserved and uncommitted memory in the user mode portion of the virtual address space of the calling process.

Regards, Geo
Ops, the right example should be:

label1.Caption := Format ('Physical Memory Available to Windows: %10.0n KB', [pMemstat.dwTotalPhys / 1024]);
ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101 or Netminder will return to finalize these if they are still open in 14 days.  Experts, please post closing recommendations before that time.

Below are your open questions as of today.  Questions which have been inactive for 21 days or longer are considered to be abandoned and for those, your options are:
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.

Click you Member Profile to view your question history and please keep them updated. If you are a KnowledgePro user, use the Power Search option to find them.  

Questions which are LOCKED with a Proposed Answer but do not help you, should be rejected with comments added.  When you grade the question less than an A, please comment as to why.  This helps all involved, as well as others who may access this item in the future.  PLEASE DO NOT AWARD POINTS TO ME.

To view your open questions, please click the following link(s) and keep them all current with updates.

To view your locked questions, please click the following link(s) and evaluate the proposed answer.

*****  E X P E R T S    P L E A S E  ******  Leave your closing recommendations.
If you are interested in the cleanup effort, please click this link 
POINTS FOR EXPERTS awaiting comments are listed in the link below
Moderators will finalize this question if in @14 days Asker has not responded.  This will be moved to the PAQ (Previously Asked Questions) at zero points, deleted or awarded.
Thanks everyone.
Moderator @ Experts Exchange
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.