更新时间:2023-11-10 09:06:10
std :: unordered_set
是连续的吗?
确切该标准并未详细介绍容器的实现... 但是该标准确实规定了一些限制实际表示的行为。
The exact implementation of containers is not detailed by the standard... however the standard does prescribes a number of behaviors which constrains the actual representation.
例如, std :: unordered_set
必须是内存稳定的:对元素的引用/地址即使在添加/删除 other 元素时也有效
For example, std::unordered_set
is required to be memory stable: a reference to/address of an element is valid even when adding/removing other elements.
实现此目标的唯一方法是或多或少地独立分配元素。使用连续的内存分配无法实现此目的,因为这样的分配必然会受到限制,因此可能会变得过于庞大,无法在更大的块中重新分配元素。
The only way to achieve this is by allocating elements more or less independently. It cannot be achieved with a contiguous memory allocation as such an allocation would necessarily be bounded, and thus could be overgrown with no possibility of re-allocating the elements in a bigger chunk.