4 ms·
malloc aligns very conservatively (because it doesn't know the size of the data you're allocating for), so there are some space gains to be had there. AFAIK al
by cnity 6y ago
malloc aligns very conservatively (because it doesn't know the size of the data you're allocating for), so there are some space gains to be had there.
AFAIK also malloc will call sbrk quite a lot, at least from my cursory reading of this musl implementation[0].
[0] https://git.musl-libc.org/cgit/musl/tree/src/malloc/malloc.c?id=e5d78fe8df9bd61940abcd98ad07ed69b7da4350#n349 https://git.musl-libc.org/cgit/musl/tree/src/malloc/malloc.c...
- CyberDildonics 6y agoThat doesn't contain calls to sbrk at all, it maps memory in with mmap which is typical of every modern memory allocator.
- cnity 6y agoYou're right, I misinterpreted the calls to __brk
- quantumofalpha 6y agoIt uses both brk/sbrk ("__brk()" in that code) and mmap, the latter for allocating larger bits of memory. GNU libc does the same thing from what I remember from straces.