Skip to content

Commit be8092f

Browse files
committed
When there is not enough free space, but a matching hole on the other side, use it.
1 parent 5bdb8c4 commit be8092f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

supervisor/shared/memory.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ supervisor_allocation* allocate_memory(uint32_t length, bool high) {
125125
supervisor_allocation* alloc;
126126
for (; index < CIRCUITPY_SUPERVISOR_ALLOC_COUNT; index += direction) {
127127
alloc = &allocations[index];
128-
if (alloc->length == FREE) {
128+
if (alloc->length == FREE && (high_address - low_address) * 4 >= (int32_t) length) {
129129
break;
130130
}
131131
// If a hole matches in length exactly, we can reuse it.
@@ -134,7 +134,7 @@ supervisor_allocation* allocate_memory(uint32_t length, bool high) {
134134
return alloc;
135135
}
136136
}
137-
if (index >= CIRCUITPY_SUPERVISOR_ALLOC_COUNT || (high_address - low_address) * 4 < (int32_t) length) {
137+
if (index >= CIRCUITPY_SUPERVISOR_ALLOC_COUNT) {
138138
return NULL;
139139
}
140140
if (high) {

0 commit comments

Comments
 (0)