What is malloc doing, anyway?
Comments
Ranked by a public rubric, not by votes: what a comment adds counts, not who wrote it. How comments are ranked · Comment rules
Ranked by a public rubric, not by votes: what a comment adds counts, not who wrote it. How comments are ranked · Comment rules
Summary
Ben Andrew builds a toy malloc in stages (bump allocator, free list with splitting and coalescing, heap trimming, mmap for blocks of 128 KiB or more) and compares each with glibc. On a 500,000-step benchmark on one Xeon, glibc takes 0.0789 µs per step, while the free-list and trim versions run 65 and 142 times slower. The toy versions release memory better, but glibc's size bins and tcache buy speed at the cost of retained RSS. The figures are the author's own, from a single workload and machine.