MFC-GetNativeSystemInfo获取当前CPU信息

发布时间 2023-04-21 09:50:09作者: 天子骄龙

 

    CString str;

    SYSTEM_INFO lpSystemInfo;
    GetNativeSystemInfo(&lpSystemInfo);//获取当前CPU信息
    /*
    在一个64位的应用中调用此函数,那它等效于GetSystemInfo
    
    */

    WORD w = lpSystemInfo.wProcessorArchitecture; //处理器的体系结构
    //w=9
    str.Format(_T("w=%d\r\n"),w );
    ::OutputDebugString(str);

    WORD w1 = lpSystemInfo.dwPageSize;//指定页面的大小和页面保护和委托的颗粒。这是被 VirtualAlloc 函数使用的页大小
    //w1=4096    
    str.Format(_T("w1=%d\r\n"), w1);
    ::OutputDebugString(str);

    LPVOID p=lpSystemInfo.lpMinimumApplicationAddress;//指向应用程序和动态链接库(DLL)可以访问的最低内存地址
    
    LPVOID p1 = lpSystemInfo.lpMaximumApplicationAddress;//指向应用程序和动态链接库(DLL)可以访问的最高内存地址

    DWORD_PTR ptr = lpSystemInfo.dwActiveProcessorMask;
    /*指定一个用来代表这个系统中装配了的中央处理器的掩码。二进制0位是处理器0;31位是处理器31
    ptr=15
    【15的二进制就是1111,所以本机有4个CPU】
    */
    str.Format(_T("ptr=%d\r\n"), ptr);
    ::OutputDebugString(str);

    DWORD w2=lpSystemInfo.dwNumberOfProcessors;//指定系统中的处理器的数目
    str.Format(_T("w2=%d\r\n"), w2);
    ::OutputDebugString(str);

    DWORD w3 = lpSystemInfo.dwProcessorType;//中央处理器的类型
    str.Format(_T("w3=%d\r\n"), w3);
    ::OutputDebugString(str);

    DWORD w4 = lpSystemInfo.dwAllocationGranularity;//虚拟内存空间的粒度
    //w4=65536
    str.Format(_T("w4=%d\r\n"), w4);
    ::OutputDebugString(str);

    WORD w5 = lpSystemInfo.wProcessorLevel;//处理器等级
    //w5=6   i7处理器
    str.Format(_T("w5=%d\r\n"), w5);
    ::OutputDebugString(str);

    WORD w6 = lpSystemInfo.wProcessorRevision;//处理器版本
    //w6=14857
    str.Format(_T("w6=%d\r\n"), w6);
    ::OutputDebugString(str);