3 ms·
Show HN: C++ Arena Allocator That's 200x+ Faster Than GNU Malloc
My first post to HN (sorry for the clickbait-y title)!
Very excited to show that I built a C++ custom memory allocator and benchmarked it to GNU Malloc. Had some surprising results which led me into a OS/hardware rabbit hole, came out on the other side with some learning and a blog post.
Enjoy :)
- Someone 2y agoFTA: “You can't free the memory within the Arena. You have to wait and free the entire buffer at once. This is only good for certain workloads and not great for a general capacity allocator.” ⇒ this isn’t really a “C++ memory allocator”. That normally is assumed to have the three calls malloc, free and realloc and to be thread-safe. This just has the malloc, but not even in a thread-safe manner.
- jeffbee 2y agoIndeed. What this author should have compared against is not `malloc` but `std::pmr::monotonic_buffer_resource`.
- slaghate 2y agoAuthor here - thanks for the feedback! I agree this is not an apples-to-apples comparison. I've always read about how the stack was faster than the heap when it comes to memory allocation and wanted to explore that. Will definitely look into `std::pmr::monotonic_buffer_resource` for a stack to stack comparison.