tags:

views:

60

answers:

2

I'm trying to find out how to get the number of CPU cores programmatically. This is the code I'm using:

SYSTEM_INFO sysinfo;
GetSystemInfo( &sysinfo );
std::cout << "CPU count: " << sysinfo.dwNumberOfProcessors << std::endl;

This is running on Windows on the iMac i7 via Boot Camp. It would be nice to find out that Apple made a manufacturing mistake and put an 8-core in my machine instead of a 4-core.

+6  A: 

If your machine is hyper-threaded, it will have 8 virtual cores.

Check the Performance tab of the Windows Task Manager, see how many CPUs are displayed.

meagar
You're right, it shows 8 CPUs. I'm surprised I didn't notice this before.. Thanks!
StackedCrooked
+2  A: 

This is caused by Hyper-Threading in your i7 processor. You may want to use GetLogicalProcessorInformation function to obtain correct information about logical and physical cores. http://msdn.microsoft.com/en-us/library/ms683194

Zuljin