Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Count Processors using C++ under Windows

Tags:

c++

processors

Using unmanaged C++ on a Windows platform, is there a simple way to detect the number of processor cores my host machine has?

like image 995
Paul Mitchell Avatar asked May 18 '09 14:05

Paul Mitchell


1 Answers

You can use GetLogicalProcessorInformation to get the info you need.

ETA:

As mentioned in the question a commenter linked to, another (easier) way to do it would be via GetSystemInfo:

SYSTEM_INFO sysinfo;
GetSystemInfo( &sysinfo );

numCPU = sysinfo.dwNumberOfProcessors;

Seems like GetLogicalProcessorInformation would give you more detailed info, but if all you need is the number of processors, GetSystemInfo would probably work just fine.

like image 72
Eric Petroelje Avatar answered Oct 06 '22 10:10

Eric Petroelje