Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: VB5,VB6
Expertise: beginner
Oct 13, 2001

Determine memory usage

The GlobalMemoryStatus API function returns detailed information about the current load on the physical and virtual memory. You can use the following code to display the current amount of free memory:

    Dim ms As MEMORYSTATUS
    Dim msg As String
    
    ' query for memory data
    ms.dwLength = Len(ms)
    GlobalMemoryStatus ms
    ' create a result message.
    msg = "Total physical memory = " & GetKbytes(ms.dwTotalPhys) & vbCrLf & _
        "Available physical memory = " & GetKbytes(ms.dwAvailPhys) & vbCrLf & _
        "Memory Load = " & ms.dwMemoryLoad & "%" & vbCrLf & _
        "Total Page file = " & GetKbytes(ms.dwTotalPageFile) & vbCrLf & _
        "Available Page file = " & GetKbytes(ms.dwAvailPageFile) & vbCrLf & _
        "Total Virtual memory = " & GetKbytes(ms.dwTotalVirtual) & vbCrLf & _
        "Available Virtual memory = " & GetKbytes(ms.dwAvailVirtual)
    MsgBox msg, vbInformation, "Memory information"
The GetKbytes function is a simple routine that converts a number of bytes into Kbytes, and adds thousand separators:

' Format a memory amoung as a Kbyte or Megabyte

Function GetKbytes(ByVal amount As Long) As String
    ' convert to Kbytes
    amount = amount \ 1024
    GetKbytes = Format(amount, "###,###,###K")
End Function
Francesco Balena
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date