Page 1 of 1

How to get info about CPU?

Posted: Fri Mar 06, 2009 12:12 pm
by cas
Does anyone know how can i get CPU name and speed using api on intel mac?
Thanks

Posted: Fri Mar 06, 2009 1:27 pm
by Progi1984

Posted: Sat Mar 07, 2009 3:11 pm
by cas
Thanks Progi1984.
But, i was hoping that someone already have some small example.

Posted: Sat Mar 07, 2009 4:39 pm
by Progi1984
Sorry, but I run actually only on Windows & Linux.

Posted: Fri Apr 10, 2009 7:14 am
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.

Posted: Fri Apr 10, 2009 9:48 pm
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)

Posted: Fri Apr 10, 2009 10:58 pm
by Airr
Change length.l to:

Code: Select all

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

AIR.

Posted: Fri Apr 10, 2009 11:00 pm
by jack
yea, I realized that SizeOf don't work here.