15 #elif defined(__unix__) || defined(__unix) || defined(unix) || (defined(__APPLE__) && defined(__MACH__))
17 #include <sys/resource.h>
19 #if defined(__APPLE__) && defined(__MACH__)
20 #include <mach/mach.h>
22 #elif (defined(_AIX) || defined(__TOS__AIX__)) || (defined(__sun__) || defined(__sun) || defined(sun) && (defined(__SVR4) || defined(__svr4__)))
26 #elif defined(__linux__) || defined(__linux) || defined(linux) || defined(__gnu_linux__)
32 #error "Cannot define getPeakRSS( ) or getCurrentRSS( ) for an unknown OS."
44 PROCESS_MEMORY_COUNTERS info;
45 GetProcessMemoryInfo( GetCurrentProcess( ), &info,
sizeof(info) );
46 return (
size_t)info.WorkingSetSize;
48 #elif defined(__APPLE__) && defined(__MACH__)
50 struct mach_task_basic_info info;
51 mach_msg_type_number_t infoCount = MACH_TASK_BASIC_INFO_COUNT;
52 if ( task_info( mach_task_self( ), MACH_TASK_BASIC_INFO,
53 (task_info_t)&info, &infoCount ) != KERN_SUCCESS )
55 return (
size_t)info.resident_size;
57 #elif defined(__linux__) || defined(__linux) || defined(linux) || defined(__gnu_linux__)
61 if ( (fp = fopen(
"/proc/self/statm",
"r" )) == NULL )
63 if ( fscanf( fp,
"%*s%ld", &rss ) != 1 )
69 return (
size_t)rss * (size_t)sysconf( _SC_PAGESIZE);