944,123 Members | Top Members by Rank

Ad:
Dec 21st, 2006
0

Amount of virtual memory available?

Expand Post »
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?

Thanks

Eddie
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
eddie-jdp is offline Offline
9 posts
since Dec 2006
Dec 21st, 2006
0

Re: Amount of virtual memory available?

Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2283
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,961 posts
since Aug 2005
Dec 22nd, 2006
0

Re: Amount of virtual memory available?

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.

Eddie
Reputation Points: 10
Solved Threads: 0
Newbie Poster
eddie-jdp is offline Offline
9 posts
since Dec 2006
Dec 22nd, 2006
1

Re: Amount of virtual memory available?

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.
.dwAvailPageFileage 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.
Pascal and Delphi Syntax (Toggle Plain Text)
  1. var
  2. Status : TMemoryStatus;
  3. begin
  4. Status.dwLength := sizeof( TMemoryStatus ) ;
  5. GlobalMemoryStatus( Status ) ;

and using systeminfo

Pascal and Delphi Syntax (Toggle Plain Text)
  1. procedure TForm1.Button1Click(Sender: TObject) ;
  2. var MemoryStatus: TMemoryStatus;
  3. begin
  4. Memo1.Lines.Clear;
  5. MemoryStatus.dwLength := SizeOf(MemoryStatus) ;
  6. GlobalMemoryStatus(MemoryStatus) ;
  7. with MemoryStatus do begin
  8. Memo1.Lines.Add(IntToStr(dwLength) +
  9. ' Size of ''MemoryStatus'' record') ;
  10. Memo1.Lines.Add(IntToStr(dwMemoryLoad) +
  11. '% memory in use') ;
  12. Memo1.Lines.Add(IntToStr(dwTotalPhys) +
  13. ' Total Physical Memory in bytes') ;
  14. Memo1.Lines.Add(IntToStr(dwAvailPhys) +
  15. ' Available Physical Memory in bytes') ;
  16. Memo1.Lines.Add(IntToStr(dwTotalPageFile) +
  17. ' Total Bytes of Paging File') ;
  18. Memo1.Lines.Add(IntToStr(dwAvailPageFile) +
  19. ' Available bytes in paging file') ;
  20. Memo1.Lines.Add(IntToStr(dwTotalVirtual) +
  21. ' User Bytes of Address space') ;
  22. Memo1.Lines.Add(IntToStr(dwAvailVirtual) +
  23. ' Available User bytes of address space') ;
  24. end;
  25. end;

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

best regards,
Reputation Points: 14
Solved Threads: 16
Junior Poster
radu84 is offline Offline
171 posts
since Dec 2006
Dec 22nd, 2006
0

Re: Amount of virtual memory available?

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.

Sincerely.

Eddie
Reputation Points: 10
Solved Threads: 0
Newbie Poster
eddie-jdp is offline Offline
9 posts
since Dec 2006
Jan 2nd, 2007
0

Re: Amount of virtual memory available?

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.

Eddie
Reputation Points: 10
Solved Threads: 0
Newbie Poster
eddie-jdp is offline Offline
9 posts
since Dec 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Pascal and Delphi Forum Timeline: The question of Pascal random command ????
Next Thread in Pascal and Delphi Forum Timeline: validate days in a month





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC