Game Development Reference
In-Depth Information
'
If you want
ll use the _getdrive() and
_getdiskfree() utility functions, which work on any ANSI-compatible system.
The return value from the _getdiskfree() function is in clusters, not in bytes,
so you have to do a little math on the results.
to check free disk space, you
Checking Memory
Checking for system RAM under Windows is a little trickier; sadly, you need to leave
ANSI compatibility behind. You should check the total physical memory installed, as
well as the available virtual memory, using Windows calls. Virtual memory is a great
thingtohaveonyoursideaslongasyouuseitwisely.You
'
ll learn more about caching
in Chapter 8, Loading and Caching Game Data, but until then you can think of it as
having a near infinite bank account with a very slow bank. If your game uses virtual
memory in the wrong way, it will slow to a crawl. You might as well grab a pencil
and sketch a storyboard of the next few minutes of your game; you
'
ll see it faster.
bool CheckMemory(
const DWORDLONG physicalRAMNeeded, const DWORDLONG virtualRAMNeeded)
{
MEMORYSTATUSEX status;
GlobalMemoryStatusEx(&status);
if (status.ullTotalPhys < physicalRAMNeeded)
{
// you don't have enough physical memory. Tell the player to go get a
// real computer and give this one to his mother.
GCC_ERROR(“CheckMemory Failure: Not enough physical memory.”);
return false;
}
// Check for enough free memory.
if (status.ullAvailVirtual < virtualRAMNeeded)
{
// you don
t have enough virtual memory available.
// Tell the player to shut down the copy of Visual Studio running in the
// background, or whatever seems to be sucking the memory dry.
GCC_ERROR(
'
CheckMemory Failure: Not enough virtual memory.
);
return false;
}
char *buff = GCC_NEW char[virtualRAMNeeded];
if (buff)
delete[] buff;
else
{
 
 
Search WWH ::




Custom Search