"rtheiss" <rt*****@yahoo. com> writes:
Hi Folks,
This is hopefully an easy question. I would like to be able to check
available system memory on a WinXP machine from within python. I've
checked the docs in the win32 modules, read the Python Cookbook, and
tried the Python Essential Reference.
No luck.
Any ideas?
Many Thanks.
Bob
P.S. using v2.2
Here is a simple script which calls the GlobalMemorySta tus function:
-----
from ctypes import *
from ctypes.wintypes import DWORD
SIZE_T = c_ulong
class _MEMORYSTATUS(S tructure):
_fields_ = [("dwLength", DWORD),
("dwMemoryLengt h", DWORD),
("dwTotalPhy s", SIZE_T),
("dwAvailPhy s", SIZE_T),
("dwTotalPageFi le", SIZE_T),
("dwAvailPageFi le", SIZE_T),
("dwTotalVirtua l", SIZE_T),
("dwAvailVirtua lPhys", SIZE_T)]
def show(self):
for field_name, field_type in self._fields_:
print field_name, getattr(self, field_name)
memstatus = _MEMORYSTATUS()
windll.kernel32 .GlobalMemorySt atus(byref(mems tatus))
memstatus.show( )
-----
On my machine, it prints this:
dwLength 32
dwMemoryLength 63
dwTotalPhys 535609344
dwAvailPhys 198139904
dwTotalPageFile 907055104
dwAvailPageFile 642375680
dwTotalVirtual 2147352576
dwAvailVirtualP hys 2117771264
See the MSDN docs for GlobalMemorySta tus to learn what the fields mean,
and <http://starship.python .net/crew/theller/ctypes> for the ctypes
module.
Thomas