[python-win32] How to calc amount of avail RAM in a process ?
Tim Roberts
timr at probo.com
Thu Jan 29 20:03:13 CET 2009
geoff wrote:
> Any tips/hints on calculating the potentially available space ?
>
Do you mean the total amount of process virtual memory space still
available? You can actually get that from the GlobalMemoryStatusEx
API. There's no Python wrapper for that, as far as I know, but here's a
ctypes wrapper. Note that this does not return the total CONTIGUOUS
memory space, but for your purposes, that's probably not critical.
from ctypes import *
from ctypes.wintypes import *
class MEMORYSTATUSEX(Structure):
_fields_ = [
('dwLength', DWORD),
('dwMemoryLoad', DWORD),
('ullTotalPhys', c_ulonglong),
('ullAvailPhys', c_ulonglong),
('ullTotalPageFile', c_ulonglong),
('ullAvailPageFile', c_ulonglong),
('ullTotalVirtual', c_ulonglong),
('ullAvailVirtual', c_ulonglong),
('ullExtendedVirtual', c_ulonglong),
]
def GlobalMemoryStatusEx():
x = MEMORYSTATUSEX()
x.dwLength = sizeof(x)
windll.kernel32.GlobalMemoryStatusEx(byref(x))
return x
z = GlobalMemoryStatusEx()
print z.ullAvailVirtual
--
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the python-win32
mailing list