How to determine the hardware (CPU and RAM) on a machine?

前端 未结 13 866
长发绾君心
长发绾君心 2020-12-31 03:29

I\'m working on a cross platform profiling suite, and would like to add information about the machine\'s CPU (architecture/clock speed/cores) and RAM(total) to the report of

13条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-12-31 03:54

    For Linux with GCC you can use a very similar solution like windows. You need to include the and you need to modify the input for the __cpuid() method based on this.

    #include 
    
    char CPUBrandString[0x40];
    unsigned int CPUInfo[4] = {0,0,0,0};
    
    __cpuid(0x80000000, CPUInfo[0], CPUInfo[1], CPUInfo[2], CPUInfo[3]);
    unsigned int nExIds = CPUInfo[0];
    
    memset(CPUBrandString, 0, sizeof(CPUBrandString));
    
    for (unsigned int i = 0x80000000; i <= nExIds; ++i)
    {
        __cpuid(i, CPUInfo[0], CPUInfo[1], CPUInfo[2], CPUInfo[3]);
    
        if (i == 0x80000002)
            memcpy(CPUBrandString, CPUInfo, sizeof(CPUInfo));
        else if (i == 0x80000003)
            memcpy(CPUBrandString + 16, CPUInfo, sizeof(CPUInfo));
        else if (i == 0x80000004)
            memcpy(CPUBrandString + 32, CPUInfo, sizeof(CPUInfo));
    }
    
    cout << "CPU Type: " << CPUBrandString << endl;
    

提交回复
热议问题