Hacker News new | ask | show | jobs
by hurril 1043 days ago
I figured as much but was unsure. So the gain is that you still take heap allocations, but you do it in a "novelty" heap allocator that you will probably dipose of entirely at some point?
1 comments

Allocation happens roughly like this:

If current top of heap + allocation size > buffer size, allocate an extra buffer for the arena. Save the current top in a temp variable. Add the allocation size to the top Return the temp variable.

It's fast, and the amortized memory overhead per allocation is near zero because you don't need to track allocation sizes or free lists, since you only free the whole arena at once (one or more buffers).

It's ideal for anything where the lifetime of allocations is known to be roughly the same. E.g. a data structure you'll free all at once.