Hi all,

I am new to windows programming. I am currently using Delphi. Is there a way to tell how much total memory (including virtual memory) is currently available on a computer.

As far as I am aware... Delphi programs start out automatically with an address space of 1 or 2 megs but more memory is automatically made available as needed by the program up until the point where the computer runs out of virtual memory.

So basically the question is...

Is there a delphi function or a win32 function that returns the amount of virtual memory that is currently available.

Any ideas?



10 Years
Discussion Span
Last Post by eddie-jdp

Ancient Dragon, thank you so much for your response. I'll have to go away and read up about the function and the SYSTEM_INFO structure that it uses.

I'll confess that at this point, I don't know how to turn the results from a populated SYSTEM_INFO structure into the data I am looking for (i.e. is it related to the page size or the minimum and maximum application addresses. I'll see if I can figure it out. Thank you so much for pointing me in the right direction. If you could be even a bit more explicit as to how to use the SYSTEM_INFO to get an Integer or Long (or Int64 or whatever) that reflects how much virtual memory can still be assigned to running programs, I would definitely appreciate the extra help. In the mean time... I'll try and figure it out.

Thanks once again.



To retrieve the current memory status, you can use the GlobalMemoryStatus() function. The TMemoryStatus contains several fields indicating the status of the memory: .dwMemoryLoad: Total memory used in percentage (%)
. .dwTotalPhys: Total physical memory in bytes.
.dwAvailPhys: Physical memory left in bytes.
.dwTotalPageFile: Total page file in bytes.
.dwAvailPageFile:Page file left in bytes.
.dwTotalVirtual: Total virtual memory in bytes.
.dwAvailVirtual: Virtual memory left in bytes.

Before presenting the memory values, convert them into giga, mega or kilobytes.

   Status : TMemoryStatus;
   Status.dwLength := sizeof( TMemoryStatus ) ;
   GlobalMemoryStatus( Status ) ;

and using systeminfo

procedure TForm1.Button1Click(Sender: TObject) ;
var MemoryStatus: TMemoryStatus;
  MemoryStatus.dwLength := SizeOf(MemoryStatus) ;
  GlobalMemoryStatus(MemoryStatus) ;
  with MemoryStatus do begin
    Memo1.Lines.Add(IntToStr(dwLength) +
      ' Size of ''MemoryStatus'' record') ;
    Memo1.Lines.Add(IntToStr(dwMemoryLoad) +
      '% memory in use') ;
    Memo1.Lines.Add(IntToStr(dwTotalPhys) +
      ' Total Physical Memory in bytes') ;
    Memo1.Lines.Add(IntToStr(dwAvailPhys) +
      ' Available Physical Memory in bytes') ;
    Memo1.Lines.Add(IntToStr(dwTotalPageFile) +
      ' Total Bytes of Paging File') ;
    Memo1.Lines.Add(IntToStr(dwAvailPageFile) +
      ' Available bytes in paging file') ;
    Memo1.Lines.Add(IntToStr(dwTotalVirtual) +
      ' User Bytes of Address space') ;
    Memo1.Lines.Add(IntToStr(dwAvailVirtual) +
      ' Available User bytes of address space') ;

try to understand this and i'm suggesting you to start reading about API and WinApi.

best regards,

Radu84's post helped me immensely with the issue I was working on.

I just wanted to say a quick thank you for the replies to this thread. I really appreciate them. Radu84, I haven't even had a chance to read your post at this point. The reason for this is that I just received word this morning that there has been a death in my immediate family. I will be travelling abroad and don't expect to have internet access for about a week.

I'll take up the work I was trying to do when I get back early in January. I just wanted to let you guys know... that my lack of response wasn't due to any unappreciation of your help. I appreciate the time and effort you have given in helping me with my question.

Therefore... please know that any lack of further responses from me for just over a week is due to know lack in appreciation.




Hi guys,

I'm now back from being with the family. Radu84, I've now had a chance to read your post. The 'dwAvailVirtual' field of the TMemoryStatus object/structure sounds like EXACTLY what I want. I'll go and try it out.

Thanks Acient Dragon and Radu84 for your responses.

Best wishes and Happy New Year.


This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.