• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Detecting CPU type
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Detecting CPU type


  • Subject: Re: Detecting CPU type
  • From: j o a r <email@hidden>
  • Date: Fri, 16 Sep 2005 10:55:09 +0200


On 16 sep 2005, at 10.41, Peter wrote:

I would like to find out CPU Type (PPC or x86), Gestalt seems to be discontinued and sysctl seems not too friendly (hw.cputype: 18 ???). Please let me know which is function or Cocoa class to be use.

Gestalt discontinued? Anyway, this snippet might get you started:

#import <mach/mach.h>
#import <sys/sysctl.h>

- (NSString *) processorType
{
#define MY_CPU_TYPE_DEFAULT @"?"

#define MY_CPU_TYPE_I386 @"i386"
#define MY_CPU_TYPE_PPC @"ppc"

host_basic_info_data_t hostInfo;
mach_msg_type_number_t infoCount = HOST_BASIC_INFO_COUNT;
kern_return_t ret = host_info (mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, &infoCount);


    if (ret == KERN_SUCCESS)
    {
        if (hostInfo.cpu_type == CPU_TYPE_POWERPC)
        {
            return MY_CPU_TYPE_PPC;
        }
        else if (hostInfo.cpu_type == CPU_TYPE_I386)
        {
            return MY_CPU_TYPE_I386;
        }
        else
        {
            NSLog(@"Unknown CPU type! (Type: %d)", hostInfo.cpu_type);
            return MY_CPU_TYPE_DEFAULT;
        }
    }
    else
    {
        NSLog(@"Failed to look up CPU type! (Error: %d)", ret);
        return MY_CPU_TYPE_DEFAULT;
    }
}


j o a r


Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Detecting CPU type (From: Peter <email@hidden>)

  • Prev by Date: Detecting CPU type
  • Next by Date: Font scaling and string size problem?!?
  • Previous by thread: Detecting CPU type
  • Next by thread: Re: Detecting CPU type
  • Index(es):
    • Date
    • Thread