Article ID: 177372
Article Last Modified on 7/1/2004
DWORD dwLength; // Size of (MEMORYSTATUS). DWORD dwMemoryLoad; // Percent of memory in use. DWORD dwTotalPhys; // Bytes of physical memory. DWORD dwAvailPhys; // Free physical memory file. DWORD dwTotalPageFile; // Bytes of paging file. DWORD dwAvailPageFile; // Free bytes of paging file. DWORD dwTotalVirtual; // User bytes of address space. DWORD dwAvailVirtual; // Free user bytes.To obtain the current memory statistics, create a program in Visual FoxPro and type the following code:
* Declare API function to retrieve memory information.
DECLARE GlobalMemoryStatus IN Win32API STRING @MemStat
#DEFINE CR CHR(13)
* long2str is passed a dwLength of 32; since structure is 32 bytes long.
* long2str is appended to a 28 byte blank buffer; a total of 32 bytes.
m.stru = long2str(32) + REPLICATE(CHR(0), 28)
=GlobalMemoryStatus(@m.stru)
* dwLength is 4 bytes, start extracting members at byte 5.
* Each member is 4 bytes long.
m.memoryload = str2long(SUBSTR(m.stru, 5, 4))
m.totalphys = str2long(SUBSTR(m.stru, 9, 4))
m.availphys = str2long(SUBSTR(m.stru, 13, 4))
m.totalpagefile = str2long(SUBSTR(m.stru, 17, 4))
m.availpagefile = str2long(SUBSTR(m.stru, 21, 4))
m.totalvirtual = str2long(SUBSTR(m.stru, 25, 4))
m.availvirtual = str2long(SUBSTR(m.stru, 29, 4))
=MESSAGEBOX("Percent memory in use: " + STR(m.memoryload) + CR + ;
"Bytes of physical memory present: " + STR(m.totalphys) + CR + ;
"Bytes available physical memory: " + STR(m.availphys) + CR + ;
"Bytes of paging file: " + STR(m.totalpagefile) + CR + ;
"Bytes available paging file: " + STR(m.availpagefile) + CR + ;
"Total virtual memory: " + STR(m.totalvirtual) + CR + ;
"Available bytes virtual memory: " + STR(m.availvirtual), ;
0 + 64 + 0, ;
"GlobalMemoryStatus() results")
*******************************************************************
FUNCTION long2str
*******************************************************************
* passed : 32-bit non-negative numeric value (m.longval).
* returns : ASCII character representation of passed value in
* low-high format (m.retstr).
* example :
* m.long = 999999
* m.longstr = long2str(m.long)
PARAMETERS m.longval
PRIVATE i, m.retstr
m.retstr = ""
FOR i = 24 TO 0 STEP -8
m.retstr = CHR(INT(m.longval/(2^i))) + m.retstr
m.longval = MOD(m.longval, (2^i))
NEXT
RETURN m.retstr
*******************************************************************
FUNCTION str2long
*******************************************************************
* passed: 4-byte character string (m.longstr) in low-high ASCII format.
* returns: Long integer value.
*
* example:
* m.longstr = "1111"
* m.longval = str2long(m.longstr)
PARAMETERS m.longstr
PRIVATE i, m.retval
m.retval = 0
FOR i = 0 TO 24 STEP 8
m.retval = m.retval + (ASC(m.longstr) * (2^i))
m.longstr = RIGHT(m.longstr, LEN(m.longstr) - 1)
NEXT
RETURN m.retval
* End of GlobalMemoryStatus code
Additional query words: API physical memory virtual memory
Keywords: kbhowto kbcode KB177372