所以我试图通过python来获得我电脑的可用内存和总内存。这就是我现在所拥有的:
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
如果我执行这个操作,我总是得到相同的可用RAM值和总RAM值。当我请求dwMemoryLoad
时,我得到的值与在窗口的任务管理器中显示的“物理内存”相同,它是已使用RAM的百分比(不是0)。但我想要精确的字节数。我做错什么了吗?在
我不能用任何额外的图书馆,如果可以的话,我早就用了。在
根据GlobalMemoryStatus MSDN entry处的注释:
在文章的顶部,有:
顺便说一句,这个函数存在于
pywin32
库中。在相关问题 更多 >
编程相关推荐