我想知道我的iPhone中可用的总RAM.为此,我使用了以下代码.
注意:请不要解释有关检索RAM统计信息的问题,例如有线,非活动,活动和免费.
mach_port_t host_port; mach_msg_type_number_t host_size; vm_size_t pagesize; host_port = mach_host_self(); host_size = sizeof(vm_statistics_data_t) / sizeof(integer_t); host_page_size(host_port,&pagesize); vm_statistics_data_t vm_stat; if (host_statistics(host_port,HOST_VM_INFO,(host_info_t)&vm_stat,&host_size) != KERN_SUCCESS) { NSLog(@"Failed to fetch vm statistics"); return; } /* Stats in bytes */ self.wired = vm_stat.wire_count * pagesize / (1024 * 1024); self.active = vm_stat.active_count * pagesize / (1024 * 1024); self.inactive = vm_stat.inactive_count * pagesize / (1024 * 1024); self.free = vm_stat.free_count * pagesize / (1024 * 1024); self.used = self.active + self.inactive + self.wired; self.total = self.used + self.free;
结果如下:
>模拟器:总内存= 2045(我的电脑包含2GB内存).似乎是对的.
>设备(iPhone 4):总内存= 390(should be 512).不正确.
>设备(iPhone 3GS):总内存= 84(should be 256).不正确.
如果这是计算iDevice的TOTAL RAM的正确方法,请告诉我?