incorrect virtual memory report using ctypes in windows
<p>i am trying to get the total/available virtual memory in python using ctypes, but it seems to be returning a highly incorrect value. below is the code i currently have</p>

<pre><code>import ctypes
import ctypes.wintypes as wintypes

def _get_virtual_size():
    class MEMORYSTATUSEX(ctypes.Structure):
        _fields_ = [("dwLength", wintypes.DWORD),
                    ("dwMemoryLoad", wintypes.DWORD),
                    ("ullTotalPhys", ctypes.c_uint64),
                    ("ullAvailPhys", ctypes.c_uint64),
                    ("ullTotalPageFile", ctypes.c_uint64),
                    ("ullAvailPageFile", ctypes.c_uint64),
                    ("ullTotalVirtual", ctypes.c_uint64),
                    ("ullAvailVirtual", ctypes.c_uint64),
                    ("ullAvailExtendedVirtual", ctypes.c_uint64)]

        def __init__(self):
            ctypes.Structure.__init__(self)
            self.dwLength = ctypes.sizeof(self)

    kernel32 = ctypes.WinDLL("kernel32", use_last_error=True)
    GlobalMemoryStatusEx = kernel32.GlobalMemoryStatusEx
    GlobalMemoryStatusEx.restype = wintypes.BOOL
    GlobalMemoryStatusEx.argtypes = [ctypes.POINTER(MEMORYSTATUSEX)]

    status = MEMORYSTATUSEX()
    if GlobalMemoryStatusEx(status):
        return {'totalPage':status.ullAvailPageFile,  'total':status.ullTotalVirtual, 'available':status.ullAvailVirtual}
    return None

print _get_virtual_size()
</code></pre>

<blockquote>
  <p>Result: {'available': 140737380003840L, 'totalPage': 13305126912L, 'total': 140737488224256L}</p>
</blockquote>

<p>Note : Using psutil the value seems to be reported correctly, but need a solution without using psutil.</p>

<pre><code>import psutil
print psutil.virtual_memory()
</code></pre>

<blockquote>
  <p>Result: svmem(total=17114841088L, available=13436207104L, percent=21.5, used=3678633984L, free=13436207104L)</p>
</blockquote>

<p>How do i get the same values reported by psutil using the ctypes method. 
I am currently running the above code in Python 2.7.10 64Bit on Windows 8.1</p>

<p>Any help would be appreciated.</p>