20 #if _MSC_VER || __MINGW32__
23 #elif defined(__APPLE__)
24 #include <mach/mach_host.h>
25 #include <mach/mach_init.h>
26 #include <mach/task.h>
27 #include <sys/sysctl.h>
29 #include <sys/sysinfo.h>
42 #if _MSC_VER || __MINGW32__
44 DWORD pid = GetCurrentProcessId();
45 PROCESS_MEMORY_COUNTERS pmc;
46 HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid);
49 if (GetProcessMemoryInfo(hProcess, &pmc,
sizeof(pmc)))
51 size = pmc.WorkingSetSize;
53 CloseHandle(hProcess);
55 #elif defined(__APPLE__)
56 struct task_basic_info t_info;
57 mach_msg_type_number_t t_info_count = TASK_BASIC_INFO_COUNT;
58 task_info(current_task(), TASK_BASIC_INFO, (task_info_t)&t_info, &t_info_count);
59 size_t size = t_info.virtual_size;
62 int size, res, shared, text, sharedLibs, stack, dirtyPages;
64 return (
size_t)size * getpagesize();
76 #if _MSC_VER || __MINGW32__
77 MEMORYSTATUSEX statex;
78 statex.dwLength =
sizeof(statex);
79 GlobalMemoryStatusEx(&statex);
80 return (
size_t)statex.ullTotalPhys;
81 #elif defined(__APPLE__)
83 int64_t physical_memory;
86 size_t length =
sizeof(int64_t);
87 sysctl(mib, 2, &physical_memory, &length, NULL, 0);
88 return physical_memory;
92 return info.totalram * info.mem_unit;
101 int *size,
int *res,
int *shared,
int *text,
int *sharedLibs,
int *stack,
int *dirtyPages)
105 f = fopen(
"/proc/self/statm",
"r");
108 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()