Available System Memory

R

rtheiss

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
 
T

Thomas Heller

rtheiss said:
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 GlobalMemoryStatus function:

-----
from ctypes import *
from ctypes.wintypes import DWORD

SIZE_T = c_ulong

class _MEMORYSTATUS(Structure):
_fields_ = [("dwLength", DWORD),
("dwMemoryLength", DWORD),
("dwTotalPhys", SIZE_T),
("dwAvailPhys", SIZE_T),
("dwTotalPageFile", SIZE_T),
("dwAvailPageFile", SIZE_T),
("dwTotalVirtual", SIZE_T),
("dwAvailVirtualPhys", SIZE_T)]
def show(self):
for field_name, field_type in self._fields_:
print field_name, getattr(self, field_name)

memstatus = _MEMORYSTATUS()
windll.kernel32.GlobalMemoryStatus(byref(memstatus))
memstatus.show()
-----

On my machine, it prints this:

dwLength 32
dwMemoryLength 63
dwTotalPhys 535609344
dwAvailPhys 198139904
dwTotalPageFile 907055104
dwAvailPageFile 642375680
dwTotalVirtual 2147352576
dwAvailVirtualPhys 2117771264

See the MSDN docs for GlobalMemoryStatus to learn what the fields mean,
and <http://starship.python.net/crew/theller/ctypes> for the ctypes
module.

Thomas
 
T

Tim Roberts

rtheiss said:
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.

The term "available system memory" basically has no meaning. On a virtual
memory system, you get as much as you need.

What problem are you really trying to solve?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top