File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change 1111#include < string>
1212#include < stdexcept>
1313
14+ // BSD like macOS does not have /proc/meminfo
15+ // include unistd.h to get the number of system memory.
16+ #if defined(__MACH__)
17+ #include < unistd.h>
18+ #endif
19+
1420namespace Comm
1521{
1622
1723namespace Global_Func
1824{
1925 inline std::size_t memory_available ()
2026 {
27+ #if defined(__MACH__)
28+ // HACK: always assume half of the system memory free. Only for build and test on macOS
29+ std::size_t pages = sysconf (_SC_PHYS_PAGES);
30+ std::size_t page_size = sysconf (_SC_PAGE_SIZE);
31+ return pages * page_size / 2 ;
32+ #else
2133 constexpr std::size_t kB_to_B = 1024 ;
2234 std::ifstream ifs (" /proc/meminfo" );
2335 int num = 0 ;
@@ -42,6 +54,7 @@ namespace Global_Func
4254 }
4355 }
4456 throw std::runtime_error (" read /proc/meminfo error in " + std::string (__FILE__) + " line " + std::to_string (__LINE__));
57+ #endif
4558 }
4659}
4760
You can’t perform that action at this time.
0 commit comments