Game Development Reference
In-Depth Information
// even though there is enough memory, it isn
t available in one
// block, which can be critical for games that manage their own memory
GCC_ERROR(
'
CheckMemory Failure: Not enough contiguous memory.
);
return false;
}
}
This function relies on the GlobalMemoryStatusEx() function, which returns the
current state of the physical and virtual memory system. In addition, this function
allocates and immediately releases a huge block of memory. This has the effect of
making Windows clean up any garbage that has accumulated in the memory man-
ager and double-checks that you can allocate a contiguous block as large as you
need. If the call succeeds, you
'
ve essentially run the equivalent of a Zamboni machine
through your system
s memory, getting it ready for your game to hit the ice. Console
programmers should nuke that bit of code
'
it simply isn
'
t needed in a system that
only runs one application at a time.
Calculating CPU Speed
Since Windows XP, the CPU speed can be read from the system registry with this
code:
DWORD ReadCPUSpeed()
{
DWORD BufSize = sizeof(DWORD);
DWORD dwMHz = 0;
DWORD type = REG_DWORD;
HKEY hKey;
// open the key where the proc speed is hidden:
long lError = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
L“HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0”,
0, KEY_READ, &hKey);
if(lError == ERROR_SUCCESS)
{
// query the key:
RegQueryValueEx(hKey, L
˜
MHz
, NULL, &type, (LPBYTE) &dwMHz, &BufSize);
}
return dwMHz;
}
If you want to calculate the CPU speed, there
s a great bit of code written by Michael
Lyons at Microsoft that does the job nicely. You can find it in the companion source
code to this topic in Dev\Source\GCC4\Mainloop\CPUSpeed.cpp.
'
 
 
Search WWH ::




Custom Search