gpt4 book ai didi

c++ - 与内存相关的“竞技场”一词的含义是什么?

转载 作者:IT老高 更新时间:2023-10-28 11:59:26 32 4
gpt4 key购买 nike

我正在阅读一本关于内存作为编程概念的书。在后面的一章中,作者大量使用了arena这个词,但从未定义它。我搜索了这个词的含义以及它与内存的关系,但一无所获。以下是作者使用该术语的一些上下文:

"The next example of serialization incorporates a strategy called memory allocation from a specific arena."

"...this is useful when dealing with memory leaks or when allocating from a specific arena."

"...if we want to deallocate the memory then we will deallocate the whole arena."

作者在一章中使用该术语超过 100 次。词汇表中的唯一定义是:

allocation from arena - Technique of allocating an arena first and then managing the allocation/deallocation within the arena by the program itself (rather then by the process memory manager); used for compaction and serialization of complex data structures and objects, or for managing memory in safety-critical and /or fault-tolerant systems.

鉴于这些情况,谁能为我定义竞技场

最佳答案

竞技场只是一 block 大的、连续的内存,您分配一次,然后通过分发部分内存来手动管理内存。例如:

char * arena = malloc(HUGE_NUMBER);

unsigned int current = 0;

void * my_malloc(size_t n) { current += n; return arena + current - n; }

关键是您可以完全控制内存分配的工作方式。唯一不受您控制的是初始分配的单个库调用。

一个流行的用例是每个 arena 仅用于分配一个固定大小的内存块。在这种情况下,您可以编写非常有效的回收算法。另一个用例是每个“任务”有一个竞技场,当您完成任务后,您可以一次性释放整个竞技场,而无需担心跟踪单个释放。

这些技术中的每一个都非常专业,通常只有在您确切知道自己在做什么以及为什么正常的库分配不够好时才会派上用场。请注意,一个好的内存分配器本身已经可以发挥很多作用,在您开始自己处理内存之前,您需要大量证据证明这还不够好。

关于c++ - 与内存相关的“竞技场”一词的含义是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12825148/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com