Amount of virtual memory available?

Reply

Join Date: Dec 2006
Posts: 9
Reputation: eddie-jdp is an unknown quantity at this point 
Solved Threads: 0
eddie-jdp eddie-jdp is offline Offline
Newbie Poster

Amount of virtual memory available?

 
0
  #1
Dec 21st, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,343
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1458
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Amount of virtual memory available?

 
0
  #2
Dec 21st, 2006
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 9
Reputation: eddie-jdp is an unknown quantity at this point 
Solved Threads: 0
eddie-jdp eddie-jdp is offline Offline
Newbie Poster

Re: Amount of virtual memory available?

 
0
  #3
Dec 22nd, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 171
Reputation: radu84 is an unknown quantity at this point 
Solved Threads: 16
radu84 radu84 is offline Offline
Junior Poster

Re: Amount of virtual memory available?

 
1
  #4
Dec 22nd, 2006
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,
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 9
Reputation: eddie-jdp is an unknown quantity at this point 
Solved Threads: 0
eddie-jdp eddie-jdp is offline Offline
Newbie Poster

Re: Amount of virtual memory available?

 
0
  #5
Dec 22nd, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 9
Reputation: eddie-jdp is an unknown quantity at this point 
Solved Threads: 0
eddie-jdp eddie-jdp is offline Offline
Newbie Poster

Re: Amount of virtual memory available?

 
0
  #6
Jan 2nd, 2007
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Pascal and Delphi Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC