Using unmanaged C++ on a Windows platform, is there a simple way to detect the number of processor cores my host machine has?
+9
A:
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.
Eric Petroelje
2009-05-18 14:05:45
Just what the Doctor order, works a treat. Thanks!
Paul Mitchell
2009-05-18 14:39:31
+1
A:
I've noticed there's an environment variable NUMBER_OF_PROCESSORS
on XP, but I couldn't find it on Microsoft's site. I believe this would be the easiest way, though.
Bastien Léonard
2009-05-18 14:20:32