관리 메뉴

MuTa

시스템 현재 코어 개수 구하기 본문

MFC-C++

시스템 현재 코어 개수 구하기

MuTa 2016. 5. 13. 13:58

//코어 갯수 구하기

#include <Windows.h>

#include <process.h>

 

int GetNumberOfCores()

{

PSYSTEM_LOGICAL_PROCESSOR_INFORMATION pProcessorInformations = NULL;

DWORD length = 0;

 

BOOL result = GetLogicalProcessorInformation(pProcessorInformations, &length);

if (!result)

{

if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)

{

pProcessorInformations = (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION)new BYTE[length];

}

}

 

result = GetLogicalProcessorInformation(pProcessorInformations, &length);

if (!result)

{

// error

return -1;

}

 

int numOfCores = 0;

for (int i = 0; i < length / sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION); i++)

{

if (pProcessorInformations[i].Relationship == RelationProcessorCore)

numOfCores++;

}

 

delete[] pProcessorInformations;

 

return numOfCores;

}

//

'MFC-C++' 카테고리의 다른 글

대용량 메모리 할당 Massive Memory Alloc  (0) 2016.05.27
C++ 11 핵심  (0) 2016.05.16
폴더내 파일 리스트 가져오기  (0) 2016.05.13
Visual C++ Tips & Tricks  (0) 2016.05.13
3차원 vector c++11  (0) 2016.05.11