From be8092f4d32d06488df88294a9dc4bb809411c5e Mon Sep 17 00:00:00 2001 From: Christian Walther Date: Fri, 2 Oct 2020 23:07:07 +0200 Subject: [PATCH] When there is not enough free space, but a matching hole on the other side, use it. --- supervisor/shared/memory.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/supervisor/shared/memory.c b/supervisor/shared/memory.c index fdb4e06fbb..0f96ae2734 100755 --- a/supervisor/shared/memory.c +++ b/supervisor/shared/memory.c @@ -125,7 +125,7 @@ supervisor_allocation* allocate_memory(uint32_t length, bool high) { supervisor_allocation* alloc; for (; index < CIRCUITPY_SUPERVISOR_ALLOC_COUNT; index += direction) { alloc = &allocations[index]; - if (alloc->length == FREE) { + if (alloc->length == FREE && (high_address - low_address) * 4 >= (int32_t) length) { break; } // If a hole matches in length exactly, we can reuse it. @@ -134,7 +134,7 @@ supervisor_allocation* allocate_memory(uint32_t length, bool high) { return alloc; } } - if (index >= CIRCUITPY_SUPERVISOR_ALLOC_COUNT || (high_address - low_address) * 4 < (int32_t) length) { + if (index >= CIRCUITPY_SUPERVISOR_ALLOC_COUNT) { return NULL; } if (high) {