GetProcesserCount() 可以采用 C/C++ 11 STL标准库:
std::thread::hardware_concurrency() 静态成员函数代替。
int GetCurrentProcessId() noexcept {
#ifdef _WIN32
return ::GetCurrentProcessId();
#else
return ::getpid();
#endif
}
int GetProcesserCount() noexcept {
int count = 0;
#if defined(_WIN32) || defined(_WIN64)
SYSTEM_INFO si;
GetSystemInfo(&si);
count = si.dwNumberOfProcessors;
#else
#if !defined(ANDROID) || __ANDROID_API__ >= 23
count = get_nprocs();
#else
count = sysconf(_SC_NPROCESSORS_ONLN);
#endif
#endif
if (count < 1) {
count = 1;
}
return count;
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)