Comment by throwaway2027
11 hours ago
When dealing with memory in C defaulting to malloc or some opaque structure behind it is unless you just want to allocate and forget it for some one off program that frees memory on proc exit seems bad to me now. For any kind of sophisticated system or module you almost always want to write your own variety of slab, arena, pool, bump whatever it may be allocator.
People get excited about custom allocators until they hit subtle fragmentation bugs or botch thread safety under load. Explicit heaps are nice for metrics and debugging, but once a busy codebase has objects crossing module boundaries, the lifetime rules get ugly fast and the malloc overhead you were trying to dodge often looks cheap.
Most teams get this wrong. If you care about valgrind, ASan, and heap dumps, rolling your own allocator means giving up a lot of mature tooling for a problem that usually isn't where the latency or memory footprint went in the first place.