Finding out the amount of free memory
It is easy to return the amount of free memory in windows, using the
GlobalMemoryStatus API call. Insert the following into a module's declarations section:
Public Type MEMORYSTATUS
dwLength As Long
dwMemoryLoad As Long
dwTotalPhys As Long
dwAvailPhys As Long
dwTotalPageFile As Long
dwAvailPageFile As Long
dwTotalVirtual As Long
dwAvailVirtual As Long
End Type Public Declare Sub GlobalMemoryStatus _
Lib "kernel32" (lpBuffer As MEMORYSTATUS)
Now, add this code to get the
values:
Dim MS As MEMORYSTATUS
MS.dwLength = Len(MS)
GlobalMemoryStatus MS
' MS.dwMemoryLoad contains percentage memory used
' MS.dwTotalPhys contains total amount of physical memory in bytes
' MS.dwAvailPhys contains available physical memory
' MS.dwTotalPageFile contains total amount of memory in the page file
' MS.dwAvailPageFile contains available amount of memory in the page file
' MS.dwTotalVirtual contains total amount of virtual memory
' MS.dwAvailVirtual contains available virtual memory
You could use this in about boxes or
making a memory monitoring system.
|