1 // Windows/System.cpp 2 3 #include "StdAfx.h" 4 5 #include "../Common/MyWindows.h" 6 7 #include "../Common/Defs.h" 8 9 #include "System.h" 10 11 namespace NWindows { 12 namespace NSystem { 13 14 #ifdef _WIN32 15 GetNumberOfProcessors()16UInt32 GetNumberOfProcessors() 17 { 18 SYSTEM_INFO systemInfo; 19 GetSystemInfo(&systemInfo); 20 return (UInt32)systemInfo.dwNumberOfProcessors; 21 } 22 23 #else 24 25 UInt32 GetNumberOfProcessors() 26 { 27 return 1; 28 } 29 30 #endif 31 32 33 #ifdef _WIN32 34 35 #ifndef UNDER_CE 36 37 #if !defined(_WIN64) && defined(__GNUC__) 38 39 typedef struct _MY_MEMORYSTATUSEX { 40 DWORD dwLength; 41 DWORD dwMemoryLoad; 42 DWORDLONG ullTotalPhys; 43 DWORDLONG ullAvailPhys; 44 DWORDLONG ullTotalPageFile; 45 DWORDLONG ullAvailPageFile; 46 DWORDLONG ullTotalVirtual; 47 DWORDLONG ullAvailVirtual; 48 DWORDLONG ullAvailExtendedVirtual; 49 } MY_MEMORYSTATUSEX, *MY_LPMEMORYSTATUSEX; 50 51 #else 52 53 #define MY_MEMORYSTATUSEX MEMORYSTATUSEX 54 #define MY_LPMEMORYSTATUSEX LPMEMORYSTATUSEX 55 56 #endif 57 58 typedef BOOL (WINAPI *GlobalMemoryStatusExP)(MY_LPMEMORYSTATUSEX lpBuffer); 59 60 #endif 61 62 #endif 63 64 GetRamSize(UInt64 & size)65bool GetRamSize(UInt64 &size) 66 { 67 size = (UInt64)(sizeof(size_t)) << 29; 68 69 #ifdef _WIN32 70 71 #ifndef UNDER_CE 72 MY_MEMORYSTATUSEX stat; 73 stat.dwLength = sizeof(stat); 74 #endif 75 76 #ifdef _WIN64 77 78 if (!::GlobalMemoryStatusEx(&stat)) 79 return false; 80 size = MyMin(stat.ullTotalVirtual, stat.ullTotalPhys); 81 return true; 82 83 #else 84 85 #ifndef UNDER_CE 86 GlobalMemoryStatusExP globalMemoryStatusEx = (GlobalMemoryStatusExP) 87 ::GetProcAddress(::GetModuleHandle(TEXT("kernel32.dll")), "GlobalMemoryStatusEx"); 88 if (globalMemoryStatusEx && globalMemoryStatusEx(&stat)) 89 { 90 size = MyMin(stat.ullTotalVirtual, stat.ullTotalPhys); 91 return true; 92 } 93 #endif 94 95 { 96 MEMORYSTATUS stat2; 97 stat2.dwLength = sizeof(stat2); 98 ::GlobalMemoryStatus(&stat2); 99 size = MyMin(stat2.dwTotalVirtual, stat2.dwTotalPhys); 100 return true; 101 } 102 103 #endif 104 105 #else 106 107 return false; 108 109 #endif 110 } 111 112 }} 113