-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemoryTest.cpp
More file actions
33 lines (32 loc) · 861 Bytes
/
Copy pathmemoryTest.cpp
File metadata and controls
33 lines (32 loc) · 861 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//
// Created by ytech on 2021/11/2.
//
#include <mach/mach.h>
#include <mach/mach_host.h>
#include <mach/processor_info.h>
float getUsageMemory()
{
float processMemory = 0;
task_vm_info_data_t info;
mach_msg_type_number_t size = TASK_VM_INFO_COUNT;
kern_return_t kerr = task_info(mach_task_self(),
TASK_VM_INFO,
(task_info_t)&info,
&size);
if (kerr == KERN_SUCCESS)
{
if (info.phys_footprint != 0 && info.phys_footprint < 0x100000000LL)
{ // iOS8
processMemory = static_cast<float>(info.phys_footprint);
}
else
{
processMemory = static_cast<float>(info.internal);
}
}
else
{
processMemory = 0;
}
return processMemory / 1000.0f;
}