Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReadMe中的获取应用占用内存方法错误 #19

Open
imwangxuesen opened this issue Jan 23, 2019 · 0 comments
Open

ReadMe中的获取应用占用内存方法错误 #19

imwangxuesen opened this issue Jan 23, 2019 · 0 comments

Comments

@imwangxuesen
Copy link

imwangxuesen commented Jan 23, 2019

 struct mach_task_basic_info info;
 mach_msg_type_number_t count = MACH_TASK_BASIC_INFO_COUNT;	
int r = task_info(mach_task_self(), MACH_TASK_BASIC_INFO, (task_info_t)& info, & count);
if (r == KERN_SUCCESS)
{
	return info.phys_footprint;
}
else
{
	return -1;
}

中的info为mach_task_basic_info,这个结构体中并没有phys_footprint变量。

int64_t usage = 0;
task_vm_info_data_t vmInfo;
mach_msg_type_number_t count = TASK_VM_INFO_COUNT;
kern_return_t kr = task_info(mach_task_self(), TASK_VM_INFO, (task_info_t) &vmInfo, &count);

if(kr != KERN_SUCCESS) {
    return -1;
}

usage = (int64_t) vmInfo.phys_footprint;

return usage;

换成这个就OK了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant