| What is malloc doing, anyway?(benmandrew.com) | |
| 255 points by benmandrew 2 days ago | 64 comments | |
tl;dr: The article walks through building a toy malloc from scratch using sbrk and mmap, explaining chunk headers, free lists, splitting/coalescing, demand paging, and trimming the heap back to the kernel. Benchmarks show the toy allocators run 65-150x slower than glibc, which stays fast by using size-segregated bins, a thread-local cache (tcache) of recently freed chunks, and an adaptive mmap threshold—trading memory overhead to avoid syscalls on the hot path. | |
HN Discussion:
| |