Calculating Free System Resources in Microsoft WindowsLast reviewed: July 22, 1997Article ID: Q61803 |
3.00 3.10
WINDOWS
kbprg
The information in this article applies to:
SUMMARYIn the Microsoft Windows graphical environment, the About dialog box in the Program Manager displays a value that indicates the amount of free system resources available at a given time. The text below documents this calculation and the methods that an application can use to calculate this figure.
MORE INFORMATIONWindows uses the same method to calculate the percentage of free system resources in each of its operating modes (real mode, standard mode, and enhanced mode under Windows 3.0, and standard mode and enhanced mode under Windows 3.1). In the Windows environment, system resources are the amount of space available in the data segment (DS) for the user dynamic-link library (DLL) or the GDI DLL. Because system resources are exhausted if either of these data segments fills up, Windows reports the smaller of the two percentages for the system. The following formula describes the calculation for Windows 3.0 and 3.1; this may or may not be accurate in future versions of Windows:
% free = min (% free of user DS, % free of GDI DS) (64K - current DS size) + free blocks in Heap % free DS = --------------------------------------------- * 100 64K - (size of statics and stack)Or, in other words:
Current free heap assuming 64K % free DS = -------------------------------- * 100 Maximum heap assuming 64KUnder Windows 3.1, an application can call the GetFreeSystemResouces function with the GFSR_SYSTEMRESOURCES value to obtain the percentage of free system resources. Because this function is not present in Windows 3.0, an application that runs in both environments must explicitly import this function from the user dynamic-link library (DLL) when the application runs under Windows 3.1. Under Windows 3.0, an application can use the GetHeapSpaces function to determine the percentage of free system resources as follows:
DWORD cbFree; WORD wFreeK, wHeapK; WORD wUserPercent, wGDIPercent, wSysPercent; cbFree = GetHeapSpaces(GetModuleHandle("USER")); wFreeK = LOWORD(cbFree) / 1024; wHeapK = HIWORD(cbFree) / 1024; wUserPercent = MulDiv(wFreeK, 100, wHeapK); cbFree = GetHeapSpaces(GetModuleHandle("GDI")); wFreeK = LOWORD(cbFree) / 1024; wHeapK = HIWORD(cbFree) / 1024; wGDIPercent = MulDiv(wFreeK, 100, wHeapK); wSysPercent = min(wUserPercent, wGDIPercent);Because this technique does not provide accurate results under Windows 3.1, an application must determine the version of Windows with which it is running and perform the calculation accordingly.
|
Additional reference words: 3.00 3.10
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |