Home | History | Annotate | Download | only in Windows
      1 // Windows/System.cpp
      2 
      3 #include "StdAfx.h"
      4 
      5 #include "../Common/Defs.h"
      6 
      7 #include "System.h"
      8 
      9 namespace NWindows {
     10 namespace NSystem {
     11 
     12 UInt32 GetNumberOfProcessors()
     13 {
     14   SYSTEM_INFO systemInfo;
     15   GetSystemInfo(&systemInfo);
     16   return (UInt32)systemInfo.dwNumberOfProcessors;
     17 }
     18 
     19 #ifndef UNDER_CE
     20 
     21 #if !defined(_WIN64) && defined(__GNUC__)
     22 
     23 typedef struct _MY_MEMORYSTATUSEX {
     24   DWORD dwLength;
     25   DWORD dwMemoryLoad;
     26   DWORDLONG ullTotalPhys;
     27   DWORDLONG ullAvailPhys;
     28   DWORDLONG ullTotalPageFile;
     29   DWORDLONG ullAvailPageFile;
     30   DWORDLONG ullTotalVirtual;
     31   DWORDLONG ullAvailVirtual;
     32   DWORDLONG ullAvailExtendedVirtual;
     33 } MY_MEMORYSTATUSEX, *MY_LPMEMORYSTATUSEX;
     34 
     35 #else
     36 
     37 #define MY_MEMORYSTATUSEX MEMORYSTATUSEX
     38 #define MY_LPMEMORYSTATUSEX LPMEMORYSTATUSEX
     39 
     40 #endif
     41 
     42 typedef BOOL (WINAPI *GlobalMemoryStatusExP)(MY_LPMEMORYSTATUSEX lpBuffer);
     43 
     44 #endif
     45 
     46 UInt64 GetRamSize()
     47 {
     48   #ifndef UNDER_CE
     49   MY_MEMORYSTATUSEX stat;
     50   stat.dwLength = sizeof(stat);
     51   #endif
     52   #ifdef _WIN64
     53   if (!::GlobalMemoryStatusEx(&stat))
     54     return 0;
     55   return MyMin(stat.ullTotalVirtual, stat.ullTotalPhys);
     56   #else
     57   #ifndef UNDER_CE
     58   GlobalMemoryStatusExP globalMemoryStatusEx = (GlobalMemoryStatusExP)
     59       ::GetProcAddress(::GetModuleHandle(TEXT("kernel32.dll")), "GlobalMemoryStatusEx");
     60   if (globalMemoryStatusEx != 0 && globalMemoryStatusEx(&stat))
     61     return MyMin(stat.ullTotalVirtual, stat.ullTotalPhys);
     62   #endif
     63   {
     64     MEMORYSTATUS stat;
     65     stat.dwLength = sizeof(stat);
     66     ::GlobalMemoryStatus(&stat);
     67     return MyMin(stat.dwTotalVirtual, stat.dwTotalPhys);
     68   }
     69   #endif
     70 }
     71 
     72 }}
     73