[PATCH] nano malloc allocator algorithm improvement
Keith Packard
keithp@keithp.com
Sun Aug 23 00:12:00 GMT 2020
Keith Packard via Newlib <newlib@sourceware.org> writes:
> Maarten van der Schrieck | Things Connected <maarten@thingsconnected.nl>
> writes:
>
>> The current nano malloc implementation has two issues reducing the amount of memory available and increasing fragmentation.
>>
>> The first issue is that sbrk() will be called to allocate a space with
>> the size of the entire requested alloc_size, even if the last free
>> chunk borders the edge of currently allocated memory. This means that
>> in a system with 20 kb of RAM, you will get ENOMEM when performing
>> this:
>
> Oh, that's a great idea. I did the same for realloc when the block was
> at the end of the heap; doing the same for malloc is a nice
> addition.
I've gone ahead and added this. Because this code is shared with
realloc, the overall impact on the code size is pretty modest. I think
it's easily worth the increase in code size because it will use ram more
efficiently now.
I can back-port this code to newlib if people are interested; certainly
having people on this list review the could would be great.
https://github.com/picolibc/picolibc/blob/main/newlib/libc/stdlib/nano-mallocr.c
--
-keith
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/newlib/attachments/20200822/67ee809a/attachment.sig>
More information about the Newlib
mailing list