Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is not a platform independent function for this that I know of. IF you plan to target multiple versions of Windows be aware that the implementation differs across some versions. I hit this problem when testing an app under NT 3.51 for instance... (archaic, I know).</p> <p>Here is some code I used for the memory side of things. This doesn't work across platforms other than windows, and will just return 0 when compiled without the WIN32 define:</p> <p>EDIT: I forgot to mention, this code divides and rounds down to the nearest MB, hence the >> 20 all over the place.</p> <pre><code>// get memory info... int getTotalRAM() { int ret = 0; #ifdef WIN32 DWORD v = GetVersion(); DWORD major = (DWORD)(LOBYTE(LOWORD(v))); DWORD minor = (DWORD)(HIBYTE(LOWORD(v))); DWORD build; if (v &lt; 0x80000000) build = (DWORD)(HIWORD(v)); else build = 0; // because compiler static links the function... BOOL (__stdcall*GMSEx)(LPMEMORYSTATUSEX) = 0; HINSTANCE hIL = LoadLibrary(L"kernel32.dll"); GMSEx = (BOOL(__stdcall*)(LPMEMORYSTATUSEX))GetProcAddress(hIL, "GlobalMemoryStatusEx"); if(GMSEx) { MEMORYSTATUSEX m; m.dwLength = sizeof(m); if(GMSEx(&amp;m)) { ret = (int)(m.ullTotalPhys&gt;&gt;20); } } else { MEMORYSTATUS m; m.dwLength = sizeof(m); GlobalMemoryStatus(&amp;m); ret = (int)(m.dwTotalPhys&gt;&gt;20); } #endif return ret; } int getAvailRAM() { int ret = 0; #ifdef WIN32 DWORD v = GetVersion(); DWORD major = (DWORD)(LOBYTE(LOWORD(v))); DWORD minor = (DWORD)(HIBYTE(LOWORD(v))); DWORD build; if (v &lt; 0x80000000) build = (DWORD)(HIWORD(v)); else build = 0; // because compiler static links the function... BOOL (__stdcall*GMSEx)(LPMEMORYSTATUSEX) = 0; HINSTANCE hIL = LoadLibrary(L"kernel32.dll"); GMSEx = (BOOL(__stdcall*)(LPMEMORYSTATUSEX))GetProcAddress(hIL, "GlobalMemoryStatusEx"); if(GMSEx) { MEMORYSTATUSEX m; m.dwLength = sizeof(m); if(GMSEx(&amp;m)) { ret = (int)(m.ullAvailPhys&gt;&gt;20); } } else { MEMORYSTATUS m; m.dwLength = sizeof(m); GlobalMemoryStatus(&amp;m); ret = (int)(m.dwAvailPhys&gt;&gt;20); } #endif return ret; } int getTotalMemory() { int ret = 0; #ifdef WIN32 DWORD v = GetVersion(); DWORD major = (DWORD)(LOBYTE(LOWORD(v))); DWORD minor = (DWORD)(HIBYTE(LOWORD(v))); DWORD build; if (v &lt; 0x80000000) build = (DWORD)(HIWORD(v)); else build = 0; // because compiler static links the function... BOOL (__stdcall*GMSEx)(LPMEMORYSTATUSEX) = 0; HINSTANCE hIL = LoadLibrary(L"kernel32.dll"); GMSEx = (BOOL(__stdcall*)(LPMEMORYSTATUSEX))GetProcAddress(hIL, "GlobalMemoryStatusEx"); if(GMSEx) { MEMORYSTATUSEX m; m.dwLength = sizeof(m); if(GMSEx(&amp;m)) { ret = (int)(m.ullTotalPhys&gt;&gt;20) + (int)(m.ullTotalVirtual&gt;&gt;20); } } else { MEMORYSTATUS m; m.dwLength = sizeof(m); GlobalMemoryStatus(&amp;m); ret = (int)(m.dwTotalPhys&gt;&gt;20) + (int)(m.dwTotalVirtual&gt;&gt;20); } #endif return ret; } int getAvailMemory() { int ret = 0; #ifdef WIN32 DWORD v = GetVersion(); DWORD major = (DWORD)(LOBYTE(LOWORD(v))); DWORD minor = (DWORD)(HIBYTE(LOWORD(v))); DWORD build; if (v &lt; 0x80000000) build = (DWORD)(HIWORD(v)); else build = 0; // because compiler static links the function... BOOL (__stdcall*GMSEx)(LPMEMORYSTATUSEX) = 0; HINSTANCE hIL = LoadLibrary(L"kernel32.dll"); GMSEx = (BOOL(__stdcall*)(LPMEMORYSTATUSEX))GetProcAddress(hIL, "GlobalMemoryStatusEx"); if(GMSEx) { MEMORYSTATUSEX m; m.dwLength = sizeof(m); if(GMSEx(&amp;m)) { ret = (int)(m.ullAvailPhys&gt;&gt;20) + (int)(m.ullAvailVirtual&gt;&gt;20); } } else { MEMORYSTATUS m; m.dwLength = sizeof(m); GlobalMemoryStatus(&amp;m); ret = (int)(m.dwAvailPhys&gt;&gt;20) + (int)(m.dwAvailVirtual&gt;&gt;20); } #endif return ret; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload