Analysis
Here we first declare a variable of the type MEMORYSTATUS. Then we pass this
variable as argument to the GlobalMemoryStatus function which we declared in
the General Declaration section of the form.
This function "populates" this MEMORYSTATUS structure with the values of the
various parameters at that instant. From these we access two parameters and
display them using a message box. Note that the MEMORYSTATUS type has many more
members, which can be used to obtain detailed info about the current memory
status of the system.
The dwTotalVirtual member gives the total virtual memory of the system. It'd
be a waste of time to explain all of them here as any decent API guide will
contain this info. Be sure to explore them and do mail me (or post a comment
here) if you need any help.
With a little work (and a few progress bars and a timer) you can design a memory
status indicator that is all yours.
A tentative Plan of Action is as follows:
- Set the Timer's interval property to a suitable value. (So that it will
refresh the status at a suitable interval)
- Set each progress bar's maximum value property to the Total value for that
particular quantity (say dwTotalPhys or dwTotalVirtual).
- In the Timer's OnTimer event handler, call the GlobalMemoryStatus function
passing it a variable of the type MEMORYSTATUS as the argument.
- Now set the Value property of the various status bars to the Available values
of the various parameters (dwAvailPhys or dwAvailVirtual) or Total - Available
if you want to display the used portion.
That's it! YVO Memstat is ready to run. (YVO = Your Very Own, just in case
you are wondering)
Do keep one thing in mind however; progress bars are somewhat heavy in terms
of memory. So your resource meter itself could end up consuming considerable
resources on its own. Fear not, this too can be overcome to a certain extent
if we use the API to create the progress bars. We'll discuss how to accomplish
this in a future article.