19 #elif defined(__APPLE__) 20 #include <mach/mach_host.h> 21 #include <mach/mach_init.h> 22 #include <mach/task.h> 23 #include <sys/sysctl.h> 25 #include <sys/sysinfo.h> 40 DWORD pid = GetCurrentProcessId();
41 PROCESS_MEMORY_COUNTERS pmc;
42 HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid);
43 if (hProcess ==
nullptr)
45 if (GetProcessMemoryInfo(hProcess, &pmc,
sizeof(pmc)))
47 size = pmc.WorkingSetSize;
49 CloseHandle(hProcess);
51 #elif defined(__APPLE__) 52 struct task_basic_info t_info;
53 mach_msg_type_number_t t_info_count = TASK_BASIC_INFO_COUNT;
54 task_info(current_task(), TASK_BASIC_INFO, (task_info_t)&t_info, &t_info_count);
55 size_t size = t_info.virtual_size;
58 int size, res, shared, text, sharedLibs, stack, dirtyPages;
60 return (
size_t)size * getpagesize();
73 MEMORYSTATUSEX statex;
74 statex.dwLength =
sizeof(statex);
75 GlobalMemoryStatusEx(&statex);
76 return (
size_t)statex.ullTotalPhys;
77 #elif defined(__APPLE__) 79 int64_t physical_memory;
82 size_t length =
sizeof(int64_t);
83 sysctl(mib, 2, &physical_memory, &length,
nullptr, 0);
84 return physical_memory;
88 return info.totalram * info.mem_unit;
97 int *size,
int *res,
int *shared,
int *text,
int *sharedLibs,
int *stack,
int *dirtyPages)
101 f = fopen(
"/proc/self/statm",
"r");
104 size_t ignored = fscanf(f,
"%d %d %d %d %d %d %d", size, res, shared, text, sharedLibs, stack, dirtyPages);
static vcl_size_t GetTotalSizeOfPhysicalRam()
static int ReadStatmFromProcFS(int *size, int *res, int *shared, int *text, int *sharedLibs, int *stack, int *dirtyPages)
static vcl_size_t GetProcessMemoryUsage()