Re: [PATCH] nano malloc allocator algorithm improvement
Keith Packard via Newlib <[email protected]>
| Newsgroups | gmane.comp.lib.newlib |
|---|---|
| Message-ID | <[email protected]> |
Keith Packard via Newlib <[email protected]> writes: > Maarten van der Schrieck | Things Connected <[email protected]> > 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
signature.asc
(application/pgp-signature, 832 B)
-----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEw4O3eCVWE9/bQJ2R2yIaaQAAABEFAl9BtFAACgkQ2yIaaQAA ABFmow//UnZOjXSXfvDAuuZkifflj4lv4ivJqN8SECdf9xFi/dl7V+b1kW/gwPuA WQvRj4BaC/dppInHDCOwWH1lfkerKxbniNghpbp8mb7sHudTZBHS2ZwAydc/fmc3 yEHg84SQ/746BJvIhoSnSx0D3NyZByQBw/u7eiWUOLmwLKvQAJo4UYbQY/OS+7Hz HYeyTrR4hRvpHa6V4eP01GxJcWkpJXXTCCYLirifnf+iyKfK+S/c4BKfYTEVIjgE lM6MuiO7mIWgtJHqPW8OOJGj939MJ2Xlqgs6MHPoqFX0QzfZOteMSttB1h2uA+YW IiUbatepn9B6zpxnByavrw2wc+LS+j3aalh3J06KG6MTPCx2g7KQdc443n3Xv1GR iI6COhY4Q4ximRJ22XwhN9M2HuEwWZhYq6GZu6r05IBVoofrlSxJFt+CvWCulj1P L2EfviTbKiao5+EN66KyPp52gHdZRI+Pjjn46K8VjnukLHX3uEzH4n2drpognpK6 3KRFZfVYnquaW33zeFyRz7BnhFriOXyRRu1nJF22fMHLmFQv2hHU1YBwKIIS/2VG NBhAvSKkc1XZwuf2KUs00VpWc3oypQmr31FXS/z3hNiD29VnniW7jUeOx/D6DtLc 8i3HBvyPsEek0ivlYKeCiL2dsri6qYmBYmvousUy+plVEua2qk8= =jb4/ -----END PGP SIGNATURE-----