logic: fixed application crash on windows if JVM tries to allocate too much memory by reducing the amount of allocated memory to the available size.
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
#include "utility/utilityWindows.h"
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
#include <Windows.h>
|
||||
|
||||
unsigned long utility::getLargestByteSizeOfAllocatableMemory()
|
||||
{
|
||||
MEMORY_BASIC_INFORMATION mbi;
|
||||
unsigned long start = 0;
|
||||
bool recording = false;
|
||||
unsigned long freestart = 0, largestFreestart = 0;
|
||||
__int64 free = 0, largestFree = 0;
|
||||
|
||||
while (true)
|
||||
{
|
||||
SIZE_T s = VirtualQuery((LPCVOID)start, &mbi, sizeof(mbi));
|
||||
if (s != sizeof(mbi)) break;
|
||||
|
||||
if (mbi.State == MEM_FREE)
|
||||
{
|
||||
if (!recording) freestart = start;
|
||||
|
||||
free += mbi.RegionSize;
|
||||
recording = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (recording)
|
||||
{
|
||||
if (free > largestFree)
|
||||
{
|
||||
largestFree = free;
|
||||
largestFreestart = freestart;
|
||||
}
|
||||
}
|
||||
free = 0;
|
||||
recording = false;
|
||||
}
|
||||
start += mbi.RegionSize;
|
||||
}
|
||||
|
||||
return largestFree;
|
||||
}
|
||||
|
||||
#endif // WIN32
|
||||
Reference in New Issue
Block a user