Solved

Get available memory for a program

Posted on 2001-07-24
4
251 Views
Last Modified: 2010-04-06
Hi,

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.

Thanks,
JDN
0
Comment
Question by:JDN
  • 2
4 Comments
 
LVL 17

Expert Comment

by:geobul
ID: 6312584
Hi,

try this:

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

About pMemstat.dw... from Help:

dwLength

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

dwMemoryLoad

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.

dwTotalPhys

Indicates the total number of bytes of physical memory.

dwAvailPhys

Indicates the number of bytes of physical memory available.

dwTotalPageFile

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.

dwAvailPageFile

Indicates the number of bytes available in the paging file.

dwTotalVirtual

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

dwAvailVirtual

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
0
 
LVL 17

Expert Comment

by:geobul
ID: 6312628
Ops, the right example should be:

label1.Caption := Format ('Physical Memory Available to Windows: %10.0n KB', [pMemstat.dwTotalPhys / 1024]);
0
 
LVL 21

Accepted Solution

by:
gemarti earned 50 total points
ID: 6313200
Which value do you want?

Take your pick


\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  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
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

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

  {retrieve the global memory status...}
  GlobalMemoryStatus(GlobalMemoryInfo);

    {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';
end;

end.
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6976031
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.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

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.
http://www.experts-exchange.com/questions/Q.20034754.html
http://www.experts-exchange.com/questions/Q.20060247.html
http://www.experts-exchange.com/questions/Q.20078853.html
http://www.experts-exchange.com/questions/Q.20090838.html
http://www.experts-exchange.com/questions/Q.20107595.html
http://www.experts-exchange.com/questions/Q.20141644.html
http://www.experts-exchange.com/questions/Q.20156077.html
http://www.experts-exchange.com/questions/Q.20174438.html
http://www.experts-exchange.com/questions/Q.20191040.html
http://www.experts-exchange.com/questions/Q.20199286.html
http://www.experts-exchange.com/questions/Q.20201528.html
http://www.experts-exchange.com/questions/Q.20225611.html
http://www.experts-exchange.com/questions/Q.20229350.html
http://www.experts-exchange.com/questions/Q.20229409.html
http://www.experts-exchange.com/questions/Q.20230450.html
http://www.experts-exchange.com/questions/Q.20239406.html
http://www.experts-exchange.com/questions/Q.20247213.html
http://www.experts-exchange.com/questions/Q.20257951.html
http://www.experts-exchange.com/questions/Q.20270004.html
http://www.experts-exchange.com/questions/Q.20275196.html
http://www.experts-exchange.com/questions/Q.20282031.html

To view your locked questions, please click the following link(s) and evaluate the proposed answer.
http://www.experts-exchange.com/questions/Q.20242687.html

*****  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
http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643
POINTS FOR EXPERTS awaiting comments are listed in the link below
http://www.experts-exchange.com/commspt/Q.20277028.html
 
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.
Moondancer
Moderator @ Experts Exchange
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now