How to get info about CPU?

Mac OSX specific forum
cas
Enthusiast
Enthusiast
Posts: 597
Joined: Mon Nov 03, 2008 9:56 pm

How to get info about CPU?

Post by cas »

Does anyone know how can i get CPU name and speed using api on intel mac?
Thanks
cas
Enthusiast
Enthusiast
Posts: 597
Joined: Mon Nov 03, 2008 9:56 pm

Post by cas »

Thanks Progi1984.
But, i was hoping that someone already have some small example.
User avatar
Progi1984
Addict
Addict
Posts: 806
Joined: Fri Feb 25, 2005 1:01 am
Location: France > Rennes
Contact:

Post by Progi1984 »

Sorry, but I run actually only on Windows & Linux.
User avatar
Airr
User
User
Posts: 49
Joined: Tue Oct 04, 2005 4:29 am
Contact:

Post by Airr »

It should be fairly simple to translate the following C code, If you don't mind parsing a string:

Code: Select all

char* cpu_brand() {
    static char buffer[128];
    size_t length = sizeof(buffer);
    sysctlbyname("machdep.cpu.brand_string", &buffer, &length, NULL, 0);
    return buffer;    
}
What I get is the following output:
Intel(R) Core(TM)2 Duo CPU E4600 @ 2.40GHz
The above should work on both Intel and PPC Mac systems.

Do "man sysctlbyname" for more info....

AIR.
"Programming is like Poetry. Sometimes the words just escape you..." -me, to my manager.
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

Post by jack »

I tried this but get nothing
[edit] it works [/edit]

Code: Select all

ImportC "/usr/lib/libc.dylib";"/usr/lib/libSystem.B.dylib"
  sysctlbyname.l(s.s,*buffer,*length,*null,*null2)
EndImport
*buffer = AllocateMemory(128)
length.l=MemorySize(*buffer)
err.l=sysctlbyname("machdep.cpu.brand_string", *buffer, @length, 0, 0);
MessageRequester(" ",PeekS(*buffer), 0)
Last edited by jack on Fri Apr 10, 2009 11:39 pm, edited 2 times in total.
User avatar
Airr
User
User
Posts: 49
Joined: Tue Oct 04, 2005 4:29 am
Contact:

Post by Airr »

Change length.l to:

Code: Select all

length.l=MemorySize(*buffer)
SizeOf() won't work here.....

AIR.
"Programming is like Poetry. Sometimes the words just escape you..." -me, to my manager.
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

Post by jack »

yea, I realized that SizeOf don't work here.
Post Reply