gpt4 book ai didi

ios - 如何在 iOS 上检测双核 CPU?

转载 作者:IT王子 更新时间:2023-10-29 07:55:24 25 4
gpt4 key购买 nike

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

所以,我想检测双核设备(目前只有 iPad 2)并适当调整并发限制。我知道我不应该检查型号,而是检查设备特性。那么我应该寻找什么设备功能来告诉我 cpu 是否是双核的?

最佳答案

方法一

[[NSProcessInfo processInfo] activeProcessorCount];

NSProcessInfo 也有一个 processorCount 属性。了解差异 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);
}

方法三

#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 - 如何在 iOS 上检测双核 CPU?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7241936/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com