Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I detect a dual core CPU on iOS?

Tags:

ios

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.

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?

like image 262
damian Avatar asked Aug 30 '11 10:08

damian


People also ask

How do I know if I have a dual core CPU?

Look under the "System" heading to where it says "Processor." Next to processor, you will see the name of the processor you have. If it says "dual processor," this means you have two processors. If it says "dual core," this means you have a dual-core processor.

How do I know if I have dual or quad core?

To find how many cores your current computer is running, for Windows users, simply pull up the Windows Task Manager by pressing the Ctrl + Alt + Delete keys and clicking on the Task Manager button. Next click on the performance tab. The number of cores is listed on the bottom right.


1 Answers

Method 1

[[NSProcessInfo processInfo] activeProcessorCount]; 

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

Method 2

#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); } 

Method 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; } 
like image 89
albertamg Avatar answered Sep 24 '22 08:09

albertamg