This article is from: https://www.quora.com/In-C++-what-is-a-memory-arena
The original author holds the copyright.
A memory arena is simply a large, contiguous chunk of memory that is allocated once and then used to manage memory manually by handing out smaller chunks of that memory.
The point of all this is usually to improve performance when you know how you will be using memory. For example, you may be allocating and deallocating blocks only of a fixed size, in which case you can write very efficient reclamation algorithms. Often when using memory arenas you can also free the entire arena at once when you are finished with it, instead of requiring individual calls to library free functions for each small chunk. When you have many small chunks of memory this can reduce overhead significantly.
When using C++, it should be noted that if you are allocating objects from an arena and you want fast deallocation of the entire arena you should consider if you need destructors to be called. If so, this will require calling them manually on all the objects within the arena. Along these lines, if you can place only POD types in your arena you will be able to reduce allocation/deallocation overhead to a minimum.

本文介绍了C++中内存池的概念及其使用方式。内存池是一种分配大量连续内存块的方法,通过手动管理这些内存来提高程序效率。特别适用于固定大小内存块的频繁分配与释放场景,并能显著减少内存管理开销。

638

被折叠的 条评论
为什么被折叠?



