May 8, 1995
You can use the Windows® application programming interface (API) MemManInfo function to determine how much random access memory (RAM) is installed in the computer system. This article explains how to retrieve the amount of RAM.
The Windows® application programming interface (API) MemManInfo function can be called to determine how much random access memory (RAM) is installed in your computer. This function is included in the TOOLHELP.DLL file.
To use the MemManInfo function in a Visual Basic® application, you must declare the function as follows:
Private Declare Function MemManInfo% Lib "Toolhelp.dll" (lpmmi As TagMemManInfo)
The MemManInfo function takes only one argument: a structure that will hold information about the memory manager. The number of pages of memory is stored in the wPageSize field of this structure. We need only multiply the number of pages found by a value of 4 to calculate how much RAM is installed.
The example program below shows how to retrieve the amount of RAM installed in the computer system.
Private Sub Form_Load()
Dim R As Long
Text1.Text = "Total RAM installed: "
R = GetRAMSize
Text1.Text = Text1.Text + Str(R)
End Sub
Type TagMemManInfo
dwSize As Long
dwLargestFreeBlock As Long
dwMaxPagesAvailable As Long
dwMaxPagesLockable As Long
dwTotalLinearSpace As Long
dwTotalUnlockedPages As Long
dwFreePages As Long
dwTotalPages As Long
dwFreeLinearSpace As Long
wPageSize As Integer
End Type
Private Declare Function MemManInfo% Lib "Toolhelp.dll" (lpmmi As TagMemManInfo)
Function GetRAMSize() As Long
Dim mmi As TagMemManInfo
mmi.dwSize = Len(mmi)
x% = MemManInfo(mmi)
If x% <> 0 Then
GetRAMSize = mmi.dwTotalPages * 4
Else
GetRAMSize = 0
End If
End Function
"Windows Questions and Answers." (MSDN Library Archive, Books and Periodicals, Microsoft Systems Journal, 1994 Volume 9, March 1994 Number 3)
"FREEMEM2: Displays System Memory Information." (MSDN Library Archive, Sample Code, Book and Periodical Samples, Microsoft Systems Journal Samples, 1994 Volume 9)