获取iOS内存使用情况
2016-09-20 11:29
375 查看
这是我自己写着玩的,如果对内存数据有要求的,可自行四舍五入。
// 获取当前设备可用内存及所占内存的头文件
#import <sys/sysctl.h>
#import <mach/mach.h>
// 获取当前设备可用内存(单位:MB)
- (IBAction)check:(id)sender {
NSString *str =[NSString
stringWithFormat:@"%f MB",[self
availableMemory]];
[[[UIAlertView
alloc] initWithTitle:@"所占内存"
message:str delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil ,
nil]
show];
}
- (double)availableMemory
{
vm_statistics_data_t vmStats;
mach_msg_type_number_t infoCount = HOST_VM_INFO_COUNT;
kern_return_t kernReturn = host_statistics(mach_host_self(),
HOST_VM_INFO,
(host_info_t)&vmStats,
ba28
&infoCount);
if (kernReturn != KERN_SUCCESS) {
return NSNotFound;
}
return ((vm_page_size *vmStats.free_count) / 1024.0) / 1024.0;
}
// 获取当前任务所占用的内存(单位:MB)
- (IBAction)currunt:(id)sender {
NSString *str =[NSString
stringWithFormat:@"%f MB",[self
usedMemory]];
[[[UIAlertView
alloc] initWithTitle:@"当前任务所占内存"
message:str delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil ,
nil]
show];
}
- (double)usedMemory
{
task_basic_info_data_t taskInfo;
mach_msg_type_number_t infoCount =
TASK_BASIC_INFO_COUNT;
kern_return_t kernReturn =
task_info(mach_task_self(),
TASK_BASIC_INFO,
(task_info_t)&taskInfo,
&infoCount);
if (kernReturn !=
KERN_SUCCESS
) {
return
NSNotFound;
}
return taskInfo.resident_size /
1024.0 / 1024.0;
}
// 获取当前设备可用内存及所占内存的头文件
#import <sys/sysctl.h>
#import <mach/mach.h>
// 获取当前设备可用内存(单位:MB)
- (IBAction)check:(id)sender {
NSString *str =[NSString
stringWithFormat:@"%f MB",[self
availableMemory]];
[[[UIAlertView
alloc] initWithTitle:@"所占内存"
message:str delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil ,
nil]
show];
}
- (double)availableMemory
{
vm_statistics_data_t vmStats;
mach_msg_type_number_t infoCount = HOST_VM_INFO_COUNT;
kern_return_t kernReturn = host_statistics(mach_host_self(),
HOST_VM_INFO,
(host_info_t)&vmStats,
ba28
&infoCount);
if (kernReturn != KERN_SUCCESS) {
return NSNotFound;
}
return ((vm_page_size *vmStats.free_count) / 1024.0) / 1024.0;
}
// 获取当前任务所占用的内存(单位:MB)
- (IBAction)currunt:(id)sender {
NSString *str =[NSString
stringWithFormat:@"%f MB",[self
usedMemory]];
[[[UIAlertView
alloc] initWithTitle:@"当前任务所占内存"
message:str delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil ,
nil]
show];
}
- (double)usedMemory
{
task_basic_info_data_t taskInfo;
mach_msg_type_number_t infoCount =
TASK_BASIC_INFO_COUNT;
kern_return_t kernReturn =
task_info(mach_task_self(),
TASK_BASIC_INFO,
(task_info_t)&taskInfo,
&infoCount);
if (kernReturn !=
KERN_SUCCESS
) {
return
NSNotFound;
}
return taskInfo.resident_size /
1024.0 / 1024.0;
}
相关文章推荐
- 获取当前ios设备的内存使用情况,获取客户端ip地址
- iOS开发--用方法获取内存使用情况
- 【IOS】IOS 获取当前内存使用情况
- 写出方法获取ios内存使用情况
- 写出方法获取ios内存使用情况。
- 获取iOS内存的使用情况
- iOS 获取当前内存使用情况
- 写出方法获取ios内存使用情况
- 获取ios内存使用情况
- ios iPhone/iPad 实时获取内存使用情况
- linux c程序获取cpu使用率及内存使用情况
- Java获取系统硬盘和内存使用情况;
- linux c程序获取cpu使用率及内存使用情况
- c++ 获取进程内存使用情况
- 如何获取进程内存使用情况
- proc文件系统中cpu,内存,网络数据使用情况获取(附检测网速源码)
- 获取内存使用情况信息 (转)
- iOS获取设备流量使用情况 iPhone Data Usage Tracking/Monitoring
- Windows下用C语言获取进程cpu使用率,内存使用,IO情况
- 在Mac上用Objective-C获取系统内存使用情况