DEV Community

Discussion on: C++ Programming: Arena Allocation

Collapse
swarnimarun profile image
Swarnim Arun • Edited on

Then maybe mention that very specific situation? Your when to use is more vague than most C++ textbooks, and man they are just horrid.

And yes Arena Allocators are pretty much useless, as we can always write stack allocators which require not anymore effort but are both robust and actually flexible.

I am curious how is Arena Allocator flexible.?
In all my experience programming I can only think of one very specific use case of something like an Arena Allocator, that would be to hold an allocation big enough to not be on stack, and small enough that it doesn't need to be optimized so above the 32mb and below 1gb around. And it needs to live and be useful for almost entire life of the program, I think you can imagine a dp table being the obvious example and yes other than that there is no viable use I can think of where stack allocator won't be much better.
Also important note, Arena Allocators need to hold the data of same size and shape for their entire lifetime, once allocated.
Because for programs running on our own system, changing stack size at link time is trivial. And to rub some salt, you can just use a malloc to pre-allocate it beforehand and just not worry about anything else...

If this article would have been Baby's first boring and yet exciting Allocator. And removes all real world examples I am perfectly fine with it.
But at this point you are selling, roller skates as a robust and flexible off-roading vehicle that everyone else is too dumb to use.

Thread Thread
aboss123 profile image
Ashish Bailkeri Author • Edited on

If you look back, the article has removed some confusing language and it is no longer called "flexible". I understand that you say arena allocation pretty much useless, but the point is to talk about this kind of allocator, it's interesting to know that is not used in many places but it is still useful enough to learn about in an article which as you say, taught to "fledgling C programmers". I never explicitly state in the article that arena allocation vastly better or worse than other allocators I only list it's benefits and I technically give an example of use case in compilers. Many people I know who are also developing their language using compilers allocate large chunks using either pools of memory or arena allocation and I use it in my own compiler. Not to say that you don't see it too often, but I see it as a useful data structure to understand in C++ and to be able to understand it you need to get off the basics.

"But at this point you are selling, roller skates as a robust and flexible off-roading vehicle that everyone else is too dumb to use."

Is listing advantages really inflating the allocation system? Every allocation system has its advantages, and so does arena allocation no matter how useless you think it is, and it also has its disadvantages many of which you have listed.

The purpose of this article is to inform, not talk about whether it is better or worse to use practically. Learning arena allocation is important to understanding how allocators can work and is good for programmers getting into this space. I hope you understand that this article is not designed to misinform about the "wonders of arena allocation", however, it is designed to list some reasons to use this and how to implement this type of allocation.

If you have any further questions on this article, feel free to let me know.