| | @@ -574,32 +574,40 @@ |
574 | 574 |
|
575 | 575 | while ( !iter.IsEnd() )
|
576 | 576 | {
|
577 | | - // Please note that by not checking the nodestack members we just try any region of same size
|
578 | | - // for allocation. It does not matter of course which one we pick.
|
579 | | - // For funny business we could randomize at this point though.
|
| 577 | + // We have to check each member of the nodestack of the current best-fit node because allocation could
|
| 578 | + // fail due to misalignment. But since we have the best-fit node going for good alignment usage
|
| 579 | + // is something the user wants: do not worry!
|
580 | 580 |
|
581 | | - VMemFreeBlock *smallFreeBlock = AVL_GETITEM( VMemFreeBlock, iter.Resolve(), sortedBySizeNode );
|
| 581 | + VMemAllocAVLTree::nodestack_iterator nodestack_iter( iter.Resolve() );
|
582 | 582 |
|
583 | | - // Try to allocate into it.
|
584 | | - // It succeeds if the allocation does fit into the free region.
|
585 | | - size_t reqSize;
|
586 | | - size_t allocOff = smallFreeBlock->freeRegion.GetSliceStartPoint();
|
| 583 | + while ( !nodestack_iter.IsEnd() )
|
| 584 | + {
|
| 585 | + VMemFreeBlock *smallFreeBlock = AVL_GETITEM( VMemFreeBlock, nodestack_iter.Resolve(), sortedBySizeNode );
|
587 | 586 |
|
588 | | - posDispatch.ScanNextBlock( allocOff, reqSize );
|
| 587 | + // Try to allocate into it.
|
| 588 | + // It succeeds if the allocation does fit into the free region.
|
| 589 | + size_t reqSize;
|
| 590 | + size_t allocOff = smallFreeBlock->freeRegion.GetSliceStartPoint();
|
589 | 591 |
|
590 | | - memBlockSlice_t requiredMemRegion( allocOff, reqSize );
|
| 592 | + posDispatch.ScanNextBlock( allocOff, reqSize );
|
591 | 593 |
|
592 | | - memBlockSlice_t::eIntersectionResult intResult = requiredMemRegion.intersectWith( smallFreeBlock->freeRegion );
|
| 594 | + memBlockSlice_t requiredMemRegion( allocOff, reqSize );
|
593 | 595 |
|
594 | | - if ( intResult == memBlockSlice_t::INTERSECT_INSIDE ||
|
595 | | - intResult == memBlockSlice_t::INTERSECT_EQUAL )
|
596 | | - {
|
597 | | - // We found a valid allocation slot!
|
598 | | - // So return it.
|
599 | | - allocPtr = (void*)allocOff;
|
600 | | - allocSlice = requiredMemRegion;
|
601 | | - freeBlockToAllocateInto = smallFreeBlock;
|
602 | | - goto foundAllocationSpot;
|
| 596 | + memBlockSlice_t::eIntersectionResult intResult = requiredMemRegion.intersectWith( smallFreeBlock->freeRegion );
|
| 597 | +
|
| 598 | + if ( intResult == memBlockSlice_t::INTERSECT_INSIDE ||
|
| 599 | + intResult == memBlockSlice_t::INTERSECT_EQUAL )
|
| 600 | + {
|
| 601 | + // We found a valid allocation slot!
|
| 602 | + // So return it.
|
| 603 | + allocPtr = (void*)allocOff;
|
| 604 | + allocSlice = requiredMemRegion;
|
| 605 | + freeBlockToAllocateInto = smallFreeBlock;
|
| 606 | + goto foundAllocationSpot;
|
| 607 | + }
|
| 608 | +
|
| 609 | + // Try the next same-size freeblock.
|
| 610 | + nodestack_iter.Increment();
|
603 | 611 | }
|
604 | 612 |
|
605 | 613 | // Try the next bigger block.
|