如何在iOS上检测双核CPU? [英] How do I detect a dual core CPU on iOS?

查看:99
本文介绍了如何在iOS上检测双核CPU?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序使用NSOperationQueue在后台线程中缓存缩略图.在iPad2上,我可以将并发任务数限制提高到5或6,但是在像iPad 1这样的单核设备上,这会使UI陷入停滞.

My app uses an NSOperationQueue to cache thumbnail images in a background thread. On the iPad2 I can push the concurrent task count limit up to 5 or 6, but on single core devices like the iPad 1 this brings the UI to a grinding halt.

因此,我想检测一个双核设备(目前只有iPad 2)并适当地调整并发限制.我知道我不应该检查型号,而要检查设备功能.那么,我应该寻找什么设备功能来告诉我CPU是否为双核?

So, I'd like to detect a dual core device (currently only iPad 2) and adapt the concurrent limit appropriately. I know I'm not supposed to check model numbers, rather device features. So what device feature should I be looking for that would tell me whether the cpu is dual core?

推荐答案

方法1

[[NSProcessInfo processInfo] activeProcessorCount];

NSProcessInfo也具有processorCount属性.在此处> .

NSProcessInfo also has a processorCount property. Learn the difference here.

#include <mach/mach_host.h>

unsigned int countCores()
{
  host_basic_info_data_t hostInfo;
  mach_msg_type_number_t infoCount;

  infoCount = HOST_BASIC_INFO_COUNT;
  host_info( mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, &infoCount ) ;

  return (unsigned int)(hostInfo.max_cpus);
}

方法3

#include <sys/sysctl.h>

unsigned int countCores()
{
  size_t len;
  unsigned int ncpu;

  len = sizeof(ncpu);
  sysctlbyname ("hw.ncpu",&ncpu,&len,NULL,0);

  return ncpu;
}

这篇关于如何在iOS上检测双核CPU?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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