win32 api获取逻辑处理器信息

来源:互联网 发布:虐杀原形1mac版下载 编辑:程序博客网 时间:2024/06/06 18:31
VOID ShowProcessors(){PSYSTEM_LOGICAL_PROCESSOR_INFORMATION pBuffer = NULL;DWORD dwSize = 0;DWORD dwProcCoreCount = 0;BOOL bResult = GetLogicalProcessorInformation( pBuffer , &dwSize );if ( GetLastError() != ERROR_INSUFFICIENT_BUFFER ){OutputDebugString(TEXT("不能获取处理器信息"));return;}pBuffer = (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION)malloc(dwSize);bResult = GetLogicalProcessorInformation( pBuffer , &dwSize );if ( !bResult ){free(pBuffer);OutputDebugString(TEXT("不能获取处理器信息"));return;}DWORD lpiCount = dwSize / sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION);for ( DWORD current = 0 ; current < lpiCount ; ++current ){if ( pBuffer[current].Relationship == RelationProcessorCore ){if ( pBuffer[current].ProcessorCore.Flags == 1 ){OutputDebugString(TEXT(" + one CPU core (HyperThreading)\n"));}else{OutputDebugString(TEXT(" + one CPU socket\n"));}++dwProcCoreCount;}}TCHAR pStr[MAX_PATH];StringCchPrintf( pStr , MAX_PATH , TEXT(" -> %d active CPU(s)\n") , dwProcCoreCount );OutputDebugString( pStr );free(pBuffer);}