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?
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.
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.
[[NSProcessInfo processInfo] activeProcessorCount];
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); }
#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; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With