Open manupedrozo opened 5 years ago
FreeListAllocator::FindBest must be rewritten
void FreeListAllocator::FindBest(const std::size_t size, const std::size_t alignment, std::size_t& padding, Node *& previousNode, Node *& foundNode)
{
std::size_t smallestDiff = std::numeric_limits<std::size_t>::max();
Node * it = m_freeList.head;
Node * itPrev {nullptr};
while (it != nullptr)
{
const std::size_t _padding = Utils::CalculatePaddingWithHeader((std::size_t)it, alignment, sizeof (FreeListAllocator::AllocationHeader));
const std::size_t requiredSpace = size + _padding;
if ( (it->data.blockSize >= requiredSpace) && ((it->data.blockSize - requiredSpace) < smallestDiff) )
{
smallestDiff = it->data.blockSize - requiredSpace;
padding = _padding;
previousNode = itPrev;
foundNode = it;
if (smallestDiff == 0)
return;
}
itPrev = it;
it = it->next;
}
}
Shouldn't the
smallestDiff
be updated along with thebestBlock
in here?if (it->data.blockSize >= requiredSpace && (it->data.blockSize - requiredSpace < smallestDiff)) {
bestBlock = it;
}
smallestDiff = it->data.blockSize
would be added.