How do I detect a dual core CPU on iOS?

前端 未结 6 516
臣服心动
臣服心动 2020-12-08 14:48

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 s

6条回答
  •  情歌与酒
    2020-12-08 15:31

    Method 1

    [[NSProcessInfo processInfo] activeProcessorCount];
    

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

    Method 2

    #include 
    
    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 
    
    unsigned int countCores()
    {
      size_t len;
      unsigned int ncpu;
    
      len = sizeof(ncpu);
      sysctlbyname ("hw.ncpu",&ncpu,&len,NULL,0);
    
      return ncpu;
    }
    

提交回复
热议问题