With the popularization of multi-core CPU, it is necessary to consider using the advantages of multi-core to improve performance in the program. For example, when creating a thread pool or process pool, you can set the thread pool or process pool size based on the number of CPU resources of the system.
The following code shows how to obtain the number of CPUs.
Typedef void (winapi * pgnsi) (lpsystem_info); <br/> DWORD getnumberofprocessors () <br/>{< br/> system_info Si; </P> <p> // call getnativesysteminfo if supported or getsysteminfo otherwise. <br/> pgnsi pfngnsi = (pgnsi) getprocaddress (getmodulehandle (_ T ("kernel32.dll"), "getnativesysteminfo"); <br/> If (pfngnsi) <br/>{< br/> pfngnsi (& Si); <br/>}< br/> else <br/>{< br/> getsysteminfo (& Si ); <br/>}< br/> return Si. dwnumberofprocessors; <br/>}
> Original article copyright belongs to the author, reprint please indicate the source and author information (http://blog.csdn.net/WinGeek/), thank you. <