So I'm trying to get the available and the total RAM of my PC via python. That's what I have by now:
def get_memory_status():
kernel32 = ctypes.windll.kernel32
c_ulong = ctypes.c_ulong
class MEMORYSTATUS(ctypes.Structure):
_fields_ = [
("dwLength", c_ulong),
("dwMemoryLoad", c_ulong),
("dwTotalPhys", c_ulong),
("dwAvailPhys", c_ulong),
("dwTotalPageFile", c_ulong),
("dwAvailPageFile", c_ulong),
("dwTotalVirtual", c_ulong),
("dwAvailVirtual", c_ulong)
]
memoryStatus = MEMORYSTATUS()
memoryStatus.dwLength = ctypes.sizeof(MEMORYSTATUS)
kernel32.GlobalMemoryStatus(ctypes.byref(memoryStatus))
return (memoryStatus.dwAvailPhys, memoryStatus.dwTotalPhys)
avail, total = get_memory_status()
print avail + " " + total
If I execute this, I always get the same values for the available and the total RAM. When i ask for dwMemoryLoad
I get the same value that is shown in Window's Task Manager as 'Physical Memory' which is the percentage of used RAM (which is not 0). But I want the precise number of bytes. Am I doing something wrong?
I can't use any extra librarys, if I could, I would already have done.