Im using:
bool GetOS(LPTSTR pszOS)
{
OSVERSIONINFOEX osve;
BOOL bOsVersionInfoEx;
ZeroMemory(&osve, sizeof(OSVERSIONINFOEX));
osve.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osve)) )
return false;
TCHAR buf[80];
StringCchPrintf( buf, 80, TEXT("%u.%u.%u.%u"),
osve.dwPlatformId,
osve.dwMajorVersion,
osve.dwMinorVersion,
osve.dwBuildNumber);
StringCchCat(pszOS, BUFSIZE, buf);
return true;
}
to get the windows version, and I am planning to use pszOS every a few minutes,
Should I use pszOS as a global var or call GetOS() every time?
What’s the best option from a performance point of view.
Using a variable is much more efficient than a function call even if the function is empty. Just make sure that you initialize this variable when you have a single thread and then don’t change it.
Does it really matter though?
From the info provided it’s hard to tell, but is it really important that this runs extremely fast? Do you use it very very very often? It’s safer to do the function call especially in a multi threaded environment. Don’t optimize prematurely if you aren’t sure this is a bottleneck in your program. Code in the safest way possible.