如何以编程方式在iPhone中查找可用内存? [英] How to find available memory in iPhone programmatically?

查看:108
本文介绍了如何以编程方式在iPhone中查找可用内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何从Objective-C中找到iPhone中可编程的可用内存?

I'd like to know how to find programmatically available memory in iPhone from Objective-C?

推荐答案

你可以使用马赫电话 host_info(host,flavor,host_info,host_info_count)。如果你用 flavor = HOST_BASIC_INFO 调用它,缓冲区 host_info 指向的是一个struct host_basic_info ,看起来像这样:

You can use the Mach call host_info(host, flavor, host_info, host_info_count). If you call it with flavor=HOST_BASIC_INFO, the buffer host_info points to is filled with a struct host_basic_info, what looks like that:

struct host_basic_info {
    integer_t               max_cpus;               /* max number of CPUs possible */
    integer_t               avail_cpus;             /* number of CPUs now available */
    natural_t               memory_size;            /* size of memory in bytes, capped at 2 GB */
    cpu_type_t              cpu_type;               /* cpu type */
    cpu_subtype_t           cpu_subtype;            /* cpu subtype */
    cpu_threadtype_t        cpu_threadtype;         /* cpu threadtype */
    integer_t               physical_cpu;           /* number of physical CPUs now available */
    integer_t               physical_cpu_max;       /* max number of physical CPUs possible */
    integer_t               logical_cpu;            /* number of logical cpu now available */
    integer_t               logical_cpu_max;        /* max number of physical CPUs possible */
    uint64_t                max_mem;                /* actual size of physical memory */
}

从这个结构中,你可以得到内存大小。

From this structure, you can get the memory size.

这篇关于如何以编程方式在iPhone中查找可用内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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