Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

When deploying an application, it may be necessary to determine whether the computer has enough memory. The Windows API function GlobalMemoryStatus returns this information, in a structure called MEMORYSTATUS.  

...

Below is the code for calling GlobalMemoryStatus.   To test, paste this code in the CLICK event of a button.  

Code Block
declare function Get_Property, Blank_Struct
declare subroutine GlobalMemoryStatus
declare subroutine Parse_Struct

gMemoryStatus = Blank_Struct("MEMORYSTATUS")
GlobalMemoryStatus(gMemoryStatus)
Parse_Struct(gMemoryStatus, "MEMORYSTATUS", length, memoryload, totalphys, availphys, totalpagefile, availpagefile, |
        total_virtual, avail_virtual)
call msg ( @window, ' Total physical memory ': totalphys / 1024 : 'KB, Available page file ': availpagefile / 1024: 'KB')

GlobalMemoryStatus can be declared as a subroutine because the return value is ignored.  

Note how the variable gMemoryStatus is allocated memory (32 bytes) required by the MEMORYSTATUS structure, using the Blank_Struct() function. Then GlobalMemoryStatus is called, filling in the gMemoryStatus variable. Finally, the Parse_Struct subroutine populates the individual variables (length, memoryload, etc.) from the gMemoryStatus structure.

...

The code above will not run until the declaration for GlobalMemoryStatus has been added.  To add the declaration, do the following:

...