gpt4 book ai didi

c++ - 为什么 C++ 分配器避免就地重新分配

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:28:44 25 4
gpt4 key购买 nike

我对 realloc 的理解是,如果内存在分配点之外连续可用,它可以尝试扩展当前分配而不进行复制。

阅读本文时 https://github.com/facebook/folly/blob/master/folly/docs/FBVector.md我开始知道大多数分配器都避免就地重新分配

. Many memory allocators do not support in- place reallocation, although most of them could. This comes from the now notorious design of realloc() to opaquely perform either in-place reallocation or an allocate-memcpy-deallocate cycle. Such lack of control subsequently forced all clib-based allocator designs to avoid in-place reallocation, and that includes C++'s new and std:allocator.

正如在另一个关于 C++ 中缺少重新分配器的问题 ( Why is there no reallocation functionality in C++ allocators? ) 中所回答的那样,接受的答案提到这样的分配器会禁止 realloc 使用 form C 库,但没有回答为什么不尝试使 realloc 扩展当前内存(如果可能)?

最佳答案

关于c++ - 为什么 C++ 分配器避免就地重新分配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25596218/

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