17 #include <sys/resource.h>
20 #if defined(__APPLE__) && defined(__MACH__)
21 #include <mach/mach.h>
23 #elif defined(__linux__) || defined(__linux) || defined(linux) || defined(__gnu_linux__)
36 getrusage(RUSAGE_SELF, &rusage);
38 #if defined(__APPLE__) && defined(__MACH__)
39 return static_cast<Float_t
>(rusage.ru_maxrss) / (1024 * 1024);
41 return static_cast<Float_t
>(rusage.ru_maxrss) / 1024;
51 #if defined(__APPLE__) && defined(__MACH__)
53 struct mach_task_basic_info info;
54 mach_msg_type_number_t infoCount = MACH_TASK_BASIC_INFO_COUNT;
55 if (task_info(mach_task_self(), MACH_TASK_BASIC_INFO, reinterpret_cast<task_info_t>(&info), &infoCount)
58 return static_cast<size_t>(0L);
59 return static_cast<size_t>(info.resident_size);
61 #elif defined(__linux__) || defined(__linux) || defined(linux) || defined(__gnu_linux__)
64 long pagesize = sysconf(_SC_PAGESIZE);
66 if ((fp = fopen(
"/proc/self/statm",
"r")) == NULL)
68 if (fscanf(fp,
"%*s%ld", &rss) != 1) {
73 if (rss > 0 && rss < std::numeric_limits<std::size_t>::max() / pagesize) {
74 return (
size_t)rss * (size_t)sysconf(_SC_PAGESIZE);
size_t GetCurrentMemory()