MCPcopy Create free account
hub / github.com/apache/arrow / GetTotalMemoryBytes

Function GetTotalMemoryBytes

cpp/src/arrow/util/io_util.cc:2216–2243  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2214}
2215
2216int64_t GetTotalMemoryBytes() {
2217#if defined(_WIN32)
2218 ULONGLONG result_kb;
2219 if (!GetPhysicallyInstalledSystemMemory(&result_kb)) {
2220 ARROW_LOG(WARNING) << "Failed to resolve total RAM size: "
2221 << std::strerror(GetLastError());
2222 return -1;
2223 }
2224 return static_cast<int64_t>(result_kb * 1024);
2225#elif defined(__APPLE__)
2226 int64_t result;
2227 size_t size = sizeof(result);
2228 if (sysctlbyname("hw.memsize", &result, &size, nullptr, 0) == -1) {
2229 ARROW_LOG(WARNING) << "Failed to resolve total RAM size";
2230 return -1;
2231 }
2232 return result;
2233#elif defined(__linux__)
2234 struct sysinfo info;
2235 if (sysinfo(&info) == -1) {
2236 ARROW_LOG(WARNING) << "Failed to resolve total RAM size: " << std::strerror(errno);
2237 return -1;
2238 }
2239 return static_cast<int64_t>(info.totalram * info.mem_unit);
2240#else
2241 return 0;
2242#endif
2243}
2244
2245Result<int32_t> GetNumAffinityCores() {
2246#if defined(__linux__)

Callers 1

TESTFunction · 0.85

Calls 1

sysinfoClass · 0.85

Tested by 1

TESTFunction · 0.68