gpt4 book ai didi

c++ - Allocator::pointer 和 Allocator::value_type* 何时不同?

转载 作者:搜寻专家 更新时间:2023-10-31 01:36:03 26 4
gpt4 key购买 nike

我对一个问题有疑问,特别是关于 this 的问题回答。
有一部分留给读者作为练习(这本身不是问题),特别是 Jonathan Wakely(答案的作者)说:

This code asserts that Allocator::pointer is Allocator::value_type*

用代码表示为:

static_assert(std::is_same<typename AT::pointer, typename AT::value_type*>::value, "Allocator doesn't use fancy pointers");

当时,我得到了原样的答案,仅此而已。
过了一会儿,当我再次阅读它时,我发现自己在大声问:花哨的指针?
来自 here (allocator_traits 的文档),pointer 定义为:

Alloc::pointer if present, otherwise value_type*

因此出现了一个问题:Allocator::pointerAllocator::value_type* 实际上不同的实际情况是什么?

最佳答案

想到的一件事是编写 allocator 规范时可能已经实现的事情。

很久以前,Intel Segmented Memory Model 中有不同类型的指针: near, far, and huge ,显示速度/大小权衡。

如今,在当前的虚拟内存架构下,它们不再有任何实际用途。不过,在旧设置中,概念上分配器可以typedef:

 typdef T *huge pointer;

它会携带比 T * 更多的信息。

关于c++ - Allocator::pointer 和 Allocator::value_type* 何时不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36238271/

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