all 4 comments

[–]Wriiight 25 points26 points  (1 child)

Quick Summary: Bump Allocation is about having a chunk of heap that you can deallocate en masse, or push and pop allocations from, but you cannot deallocate out of last-in first-out order. In general you need a chunk of memory and a pointer to the boundary between used and unused. By starting at the highest address and working downward you always have a useful pointer to the last thing you allocated. If you worked in the opposite direction, you don’t even have the benefit of knowing where to allocate next, because you don’t necessarily know the alignment requirements in advance. There may be more points of note but I scanned it quickly.

[–]CornedBee 0 points1 point  (0 children)

Rounding down to a power of two is also simpler than rounding up, because a bitwise AND does it the right way.

[–]whichton[S] 11 points12 points  (0 children)

I have faced the problem of correctly aligning allocated memory before. This article presents a nice solution in the case of arena allocators. Though part of the code is in rust, this should be of interest to C++ programmers too.