控制台里打印程序所占用的内存

控制台里打印程序所占用的内存

导入头文件:

#import

打印内存的函数:

void report_memory(void) {
    struct task_basic_info info;
    mach_msg_type_number_t size = sizeof(info);
    kern_return_t kerr = task_info(mach_task_self(), TASK_BASIC_INFO, (task_info_t)&info, &size);
    if (kerr == KERN_SUCCESS) {
        printf("Memory vm : %lu\n",info.virtual_size);
        printf("Memory in use (in bytes):%lu b\n",info.resident_size);
        printf("Memory in use (in K-bytes):%f K\n",info.resident_size/1024.0);
        printf("Memory in use (in M-bytes):%f M\n",info.resident_size/(1024.0 * 1024.0));
    } else printf("Error with task_info():%s\n",mach_error_string(kerr));
}


你可能感兴趣的:(iOS开发杂记)