Tuesday, September 12, 2006

Programmatically asking Windows how much memory you've got

If you want to know how much memory is installed in a Windows box, you can open up Task Manager and inspect the Performance tab. But what if you want your program to know how much is installed? Chances are you know what your computer has, but your program running on someone else's computer may also care to know.

Since it took just a little bit of digging, I wanted to briefly mention how to find this. The short answer is to use the GlobalMemoryStatus function.

This helpful tip is from the Win32::SystemInfo Perl module source code, the I'm Feeling Lucky link to the Google search "finding amount physical memory windows programmatically".

This is one of those things I want to put in the Software Provenance Database, a repository of information about how to find out things about your computing environment, both manually and programmatically.