Fixed 1-off bug allocating last block of MMF. Added additional heap allocation with maxmemory flag to allow for fragmentation.

This commit is contained in:
jonathan pickett
2014-02-19 18:10:05 -08:00
parent bdd9804c42
commit 208eb29003
2 changed files with 2 additions and 1 deletions
Binary file not shown.
+2 -1
View File
@@ -303,6 +303,7 @@ BOOL QForkMasterInit( __int64 maxmemoryBytes ) {
if (maxmemoryBytes != -1) {
SIZE_T allocationBlocks = maxmemoryBytes / cAllocationGranularity;
allocationBlocks += ((maxmemoryBytes % cAllocationGranularity) != 0);
allocationBlocks = (SIZE_T)ceil(allocationBlocks * 1.5); // extra reserve for fragmentation
allocationBlocks = max(2, allocationBlocks);
maxPhysicalMapping = min(maxPhysicalMapping,allocationBlocks * cAllocationGranularity);
}
@@ -961,7 +962,7 @@ LPVOID AllocHeapBlock(size_t size, BOOL allocateHigh) {
size_t mapped = 0;
int startIndex = allocateHigh ? g_pQForkControl->availableBlocksInHeap - 1 : contiguousBlocksToAllocate - 1;
int endIndex = allocateHigh ? 0 : g_pQForkControl->availableBlocksInHeap - contiguousBlocksToAllocate;
int endIndex = allocateHigh ? -1 : g_pQForkControl->availableBlocksInHeap - contiguousBlocksToAllocate + 1;
int direction = allocateHigh ? -1 : 1;
int blockIndex = 0;
int contiguousBlocksFound = 0;