When using debug (x64) in Visual Studio 2017 I have been experiencing my game sometimes act strangely.
Looking closer, it seems to have to do with memory, which I can detect if I place this in my render loop (which triggers if I load a scene containing my objects that forces the game to load many textures):
Code: Select all
// Check for not enough memory
#ifdef _DEBUG
try
{
char* tmpTest = new char[1024 * 1024 * 5]; // 5 MB
delete[] tmpTest;
}
catch(...)
{
CGeneric::ShowMessage("CApplication::frameStarted, could not allocate 5 MB, we are out of RAM!");
}
#endif
Therefore I tried another test directly in the main function:
Code: Select all
std::vector<char*> tmpMemoryAllocatedList;
long long tmpTotalMemoryAllocated = 0;
while (true)
{
try
{
const long long tmpMemoryToAllocate = 1024 * 1024 * 1; // 1 MB
char* tmpTest = new char[tmpMemoryToAllocate];
tmpMemoryAllocatedList.push_back(tmpTest);
tmpTotalMemoryAllocated += tmpMemoryToAllocate;
}
catch (...)
{
break;
}
}
for (size_t i = 0; i < tmpMemoryAllocatedList.size(); i++)
{
char* tmpTest = tmpMemoryAllocatedList[i];
delete[] tmpTest;
}
tmpMemoryAllocatedList.clear();
CGeneric::ShowMessage("Memory allocated before out of memory (MB): " + CGeneric::ToString(tmpTotalMemoryAllocated / 1024 / 1024));
return 0;
In debug it is at most 1600 MB before it just won't let me allocate more memory, but in release it allocates all the way up to 26711 MB (though that makes no sense, as I only have 16 GB RAM... Does that mean it wrote to my harddrive?).
That is almost 17 times more memory allocated in release compared to debug.
Does anyone know why this is?
How can I make debug be able to allocate more memory than just 1600 MB?
It is pretty bad for my game when debugging, I always have to avoid certain things in the game so the allocation error never happens.