Creating the MemoryStatus Class

The MemoryStatus class is one of the classes that’s centered around a single user-defined data structure, the typMemoryStatus structure.

Private Type typMemoryStatus
    lngLength As Long
    lngMemoryLoad As Long
    lngTotalPhys As Long
    lngAvailPhys As Long
    lngTotalPageFile As Long
    lngAvailPageFile As Long
    lngTotalVirtual As Long
    lngAvailVirtual As Long
End Type

To gather information about the current memory situation, call the GlobalMemoryStatus API function, passing a typMemoryStatus variable. In this case, because all the properties need to call GlobalMemoryStatus with the same data structure, the Initialize event procedure for the MemoryStatus class fills in the size of the structure, so the properties don’t all need to take this extra step:

Private Sub Class_Initialize()
    ' ms is declared at the module level.
    ms.lngLength = Len(ms)
End Sub

Once that task has been taken care of (the first time you attempt to retrieve a property of the class), retrieving any property requires only that the class call the GlobalMemoryStatus function to refresh the data structure’s values. For example, the MemoryLoad property looks like this:

Property Get MemoryLoad() As Long
    Call GlobalMemoryStatus(ms)
    MemoryLoad = ms.lngMemoryLoad
End Property

All the Property Get procedures in the MemoryStatus class work exactly the same way.

© 1997 by SYBEX Inc. All rights reserved.