Obtaining Memory Statistics & System Resources
Extract information about the current state of the system’s memory using the
GlobalMemoryStatus API function. An application can use this
function to determine how much memory it can allocate without severely
impacting other applications.
Windows 9x still uses Windows 3.x system resource structure which is two 64KB
sections of memory set aside for specific jobs. The GDI (Graphics Display
Interface) section stores fonts, bitmaps, etc for on-screen display. When an
application runs, parts of the User resources section go to their menu lists,
window logistics, and other information. Whenever you start a program it uses
some system resources but doesn't always release them when it closes.
Eventually, resources diminish until you reboot Windows.
You can determine the values that show up in the Resource Meter or that are
displayed in Explorer's Help About dialog by using the Resource
Meter's Rsrc32.dll. Again, you can check the system resources before
you shell to another application. If the resources dip below a given value you
can issue a warning message.
Download Source Code
Determining the System Resources only applies to Windows 9x machines.
You can determine the memory statistics listed in the following table by calling
the GlobalMemoryStatus API function. This function
takes a single parameter which is the MemoryStatus
structure defined below. GlobalMemoryStatus populates
the structure with the memory values.
Type MEMORYSTATUS
dwLength As Long ' sizeof(MEMORYSTATUS)
dwMemoryLoad As Long ' percent of memory in use
dwTotalPhys As Long ' bytes of physical memory
dwAvailPhys As Long ' free physical memory bytes
dwTotalPageFile As Long ' bytes of paging file
dwAvailPageFile As Long ' free bytes of paging file
dwAvailVirtual As Long ' user bytes of address space
dwTotalVirtual As Long ' free user bytes
End Type
On 9x systems you can obtain System Resource information by calling the
pBGetFreeSystemResources function in Rsrc32.dll. This dll does some
thunking and uses Rsrc16.dll. Due to the 16-bit nature of this function, it is
not available on the 32-bit NT and Windows 2000 operating systems.
Download the source code and press F5 to run the program.
|