comparison system/System.cpp @ 171:ebf55cf0d34d

* sketch win32 and os/x implementations for memory availability check
author Chris Cannam
date Tue, 26 Sep 2006 13:18:29 +0000
parents b23eea68357e
children 28c38d1e5141
comparison
equal deleted inserted replaced
170:b23eea68357e 171:ebf55cf0d34d
79 void 79 void
80 GetRealMemoryMBAvailable(int &available, int &total) 80 GetRealMemoryMBAvailable(int &available, int &total)
81 { 81 {
82 available = -1; 82 available = -1;
83 total = -1; 83 total = -1;
84
85 #ifdef _WIN32
86
87 MEMORYSTATUSEX status;
88 status.dwLength = sizeof(status);
89 if (!GlobalMemoryStatusEx(&status)) {
90 std::cerr << "WARNING: GetDiskFreeSpaceEx failed: error code "
91 << GetLastError() << std::endl;
92 return;
93 }
94 DWORDLONG size = status.ullAvailPhys / 1048576;
95 if (size > INT_MAX) size = INT_MAX;
96 available = int(size);
97
98 size = status.ullTotalPhys / 1048576;
99 if (size > INT_MAX) size = INT_MAX;
100 total = int(size);
101
102 return;
103
104 #else
105 #ifdef __APPLE__
106
107 unsigned int val;
108 int mib[2];
109 size_t size_sys;
110
111 mib[0] = CTL_HW;
112
113 mib[1] = HW_PHYSMEM;
114 size_sys = sizeof(val);
115 sysctl(mib, 2, &val, &size_sys, NULL, 0);
116 if (val) total = val / 1048576;
117
118 mib[1] = HW_USERMEM;
119 size_sys = sizeof(val);
120 sysctl(mib, 2, &val, &size_sys, NULL, 0);
121 if (val) available = val / 1048576;
122
123 return;
124
125 #else
84 126
85 FILE *meminfo = fopen("/proc/meminfo", "r"); 127 FILE *meminfo = fopen("/proc/meminfo", "r");
86 if (!meminfo) return; 128 if (!meminfo) return;
87 129
88 char buf[256]; 130 char buf[256];
110 fclose(meminfo); 152 fclose(meminfo);
111 return; 153 return;
112 } 154 }
113 } 155 }
114 fclose(meminfo); 156 fclose(meminfo);
157
158 return;
159
160 #endif
161 #endif
115 } 162 }
116 163
117 int 164 int
118 GetDiscSpaceMBAvailable(const char *path) 165 GetDiscSpaceMBAvailable(const char *path)
119 { 166 {