c++ - 分配提示是否被使用?

标签 c++ allocator

我正在阅读 Why is there no reallocation functionality in C++ allocators?Is it possible to create an array on the heap at run-time, and then allocate more space whenever needed? ,这清楚地表明不可能重新分配动态对象数组。

然而,在 Josuttis 的 The C++ Standard Library 中,它声明了一个分配器,allocator,有一个函数 allocate,语法如下

pointer allocator::allocate(size_type num, allocator<void>::pointer hint = 0)

其中 hint 具有实现定义的含义,可用于帮助提高性能。

是否有利用此优势的任何实现?

最佳答案

在我的 plf::colony 中,我在小型标量类型的迭代时间上获得了显着的性能优势c++ 容器在 Visual Studio 2010-2013 下使用带有 std::allocator 的提示(迭代速度提高了约 21%),在 GCC 5.1 下的加速比小得多。所以可以肯定地说,对于那些编译器和 std::allocator,它会有所作为。但差异将取决于编译器。我不知道提示忽略分配器与提示观察分配器的比率。

关于c++ - 分配提示是否被使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15380318/

相关文章:

c++ - 在 Boost zip 迭代器上使用 C++17 并行执行算法时,为什么会出现 MSVC 错误?

c++ - 如何跟踪列表列表的分配内存?

c++ - 动态 vector 的特征库内存使用

C++ 自定义分配器和 STL 容器

C++ 将 std::unique_ptr 作为参数传递

c++ - for 循环中的 vector 删除函数未正确删除类的 vector

c++ - 自定义 std::allocator_traits::construct

C++ - 分配器类型提供的非平凡指针的构造是否会抛出异常?

c++ - 如何在 android 中运行运行 C++ 应用程序?

c++ - 使用QPainter连接不同粗细的线条形成干净的边框