Physical RAM on win32

David Bolen db3l at fitlinxx.com
Fri Jan 11 19:03:34 EST 2002


David.Sparrman at personalchemistry.com (David Sparrman) writes:

> Is there a simple way to check the amount of physical RAM on a win32
> computer?
> There is a function GlobalMemoryStatus (and GlobalMemoryStatusEx) that
> is available from C++, but Mark Hammonds win32all does not seem to
> expose them?

That's what I ended up using, and accessed them through calldll.
Here's what I use:

   def Memory(self, machine=None):
       """Return results from GlobalMemoryStatus() call - only supported
       on local machine currently"""

       if machine:
	   raise nimgmt.Error, 'Memory statistics only available on server'

       import calldll, struct

       result   = {}
       kernel32 = calldll.load_library('kernel32')
       memstat  = calldll.get_proc_address(kernel32,'GlobalMemoryStatus')
       if memstat:
	   buf = calldll.membuf(32)
	   buf.write(struct.pack('1L',32))
	   calldll.call_foreign_function(memstat,'l','',(buf.address(),))
	   rtuple = struct.unpack('8L',buf.read())
	   result['MemoryLoad']    = rtuple[1]   # [0] is len
	   result['TotalPhys']     = rtuple[2]
	   result['AvailPhys']     = rtuple[3]
	   result['TotalPageFile'] = rtuple[4]
	   result['AvailPageFile'] = rtuple[5]
	   result['TotalVirtual']  = rtuple[6]
	   result['AvailVirtual']  = rtuple[7]
       return result

--
-- David
-- 
/-----------------------------------------------------------------------\
 \               David Bolen            \   E-mail: db3l at fitlinxx.com  /
  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
 /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \
\-----------------------------------------------------------------------/



More information about the Python-list mailing list