14 #elif defined(__unix__) || defined(__unix) || defined(unix) || \
15 (defined(__APPLE__) && defined(__MACH__))
16 #include <sys/resource.h>
19 #if defined(__APPLE__) && defined(__MACH__)
20 #include <mach/mach.h>
22 #elif (defined(_AIX) || defined(__TOS__AIX__)) || \
23 (defined(__sun__) || defined(__sun) || defined(sun) && (defined(__SVR4) || defined(__svr4__)))
27 #elif defined(__linux__) || defined(__linux) || defined(linux) || defined(__gnu_linux__)
33 #error "Cannot define getPeakRSS( ) or getCurrentRSS( ) for an unknown OS."
48 PROCESS_MEMORY_COUNTERS info;
49 GetProcessMemoryInfo(GetCurrentProcess(), &info,
sizeof(info));
50 return (
size_t)info.PeakWorkingSetSize;
52 #elif (defined(_AIX) || defined(__TOS__AIX__)) || \
53 (defined(__sun__) || defined(__sun) || defined(sun) && (defined(__SVR4) || defined(__svr4__)))
57 if ((fd = open(
"/proc/self/psinfo", O_RDONLY)) == -1)
return (
size_t)0L;
58 if (read(fd, &psinfo,
sizeof(psinfo)) !=
sizeof(psinfo)) {
63 return (
size_t)(psinfo.pr_rssize * 1024L);
65 #elif defined(__unix__) || defined(__unix) || defined(unix) || \
66 (defined(__APPLE__) && defined(__MACH__))
69 getrusage(RUSAGE_SELF, &rusage);
70 #if defined(__APPLE__) && defined(__MACH__)
71 return (
size_t)rusage.ru_maxrss;
73 return (
size_t)(rusage.ru_maxrss * 1024L);
91 PROCESS_MEMORY_COUNTERS info;
92 GetProcessMemoryInfo(GetCurrentProcess(), &info,
sizeof(info));
93 return (
size_t)info.WorkingSetSize;
95 #elif defined(__APPLE__) && defined(__MACH__)
97 struct mach_task_basic_info info;
98 mach_msg_type_number_t infoCount = MACH_TASK_BASIC_INFO_COUNT;
99 if (task_info(mach_task_self(), MACH_TASK_BASIC_INFO, (task_info_t)&info, &infoCount) !=
102 return (
size_t)info.resident_size;
104 #elif defined(__linux__) || defined(__linux) || defined(linux) || defined(__gnu_linux__)
108 if ((fp = fopen(
"/proc/self/statm",
"r")) == NULL)
return (
size_t)0L;
109 if (fscanf(fp,
"%*s%ld", &rss) != 1) {
114 return (
size_t)rss * (size_t)sysconf(_SC_PAGESIZE);
size_t getPeakRSS()
Returns the peak (maximum so far) resident set size (physical memory use) measured in bytes,...
size_t getCurrentRSS()
Returns the current resident set size (physical memory use) measured in bytes, or zero if the value c...