2007年11月19日月曜日

プロセッサの情報

コンピュータのプロパティはVistaだとこんな感じ。xpもダイアログは違うけど、プロセッサについて書かれてる。周波数は2回書かれてるし、空白のバランスが悪い。
でもこれには理由があって、赤下線部分の文字列、これはCPUから直接取得できる。こんな感じ。Visual C++依存のコードです。

#include <stdio.h>
#include <intrin.h>

int main(){
int cpuInfo[4];
__cpuid( cpuInfo, 0x80000000 );
if( cpuInfo[0] >= 0x80000004 ){
char brand[48];
__cpuid( (int*)&brand[ 0], 0x80000002 );
__cpuid( (int*)&brand[16], 0x80000003 );
__cpuid( (int*)&brand[32], 0x80000004 );
printf( "%.48s\n", &brand[0] );
}
return 0;
}

0 件のコメント: