iPhone中的总RAM [英] Total RAM in iPhone

查看:152
本文介绍了iPhone中的总RAM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道我的iPhone中可用的总计内存。为此,我使用了以下代码。

I want to know the Total RAM available in my iPhone. For this I've used the following code.

注意:请不要解释有关检索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(应为512 )。不正确。

  • 设备(iPhone 3GS):总内存= 84(应为256 )。不正确。

  • Simulator: total memory = 2045 (my PC contains 2GB RAM). Seems correct.
  • Device (iPhone 4): total memory = 390 (should be 512). Incorrect.
  • Device (iPhone 3GS): total memory = 84 (should be 256). Incorrect.

如果这是计算iDevice的 TOTAL RAM的正确方法,请告诉我。 ?

Please let me know if this is the correct way to calculate the TOTAL RAM of an iDevice?

推荐答案

您无法读取设备的总RAM。您只能读取已用空间RAM的估计值。您的设备将始终使用一些内存(用于系统,用于后台应用程序,另一个进程),因此您永远不会看到应该是512。为什么模拟器给出了接近的值?男人,这是模拟器......如果你想知道RAM,请阅读你设备的技术规格。但是根据你发布的方法(正如我所说),你将获得免费/使用过的mem。干杯。

You cannot read the total RAM of your device. You can only read an estimate of your used vs free RAM. Your device will always use some memory (for system, for background apps, another processes) so you will never see your "should be 512" totally. Why the simulator give a close value? Man, it's the simulator... If you wanna know the RAM, read the tech specs of your device. But with the method posted by you, (as I said), you'll get the free/used mem. Cheers.

这篇关于iPhone中的总RAM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆