Compelling examples of custom C++ allocators?(自定义 C++ 分配器的引人入胜的例子?)
问题描述
放弃 std::allocator
而支持自定义解决方案的真正好理由是什么?您是否遇到过对正确性、性能、可扩展性等绝对必要的情况?有什么非常聪明的例子吗?
What are some really good reasons to ditch std::allocator
in favor of a custom solution? Have you run across any situations where it was absolutely necessary for correctness, performance, scalability, etc? Any really clever examples?
自定义分配器一直是我不太需要的标准库功能.我只是想知道 SO 上是否有人可以提供一些令人信服的例子来证明它们的存在是合理的.
Custom allocators have always been a feature of the Standard Library that I haven't had much need for. I was just wondering if anyone here on SO could provide some compelling examples to justify their existence.
推荐答案
正如我所提到的 在这里,我已经看到英特尔 TBB 的自定义 STL 分配器通过更改单个
As I mention here, I've seen Intel TBB's custom STL allocator significantly improve performance of a multithreaded app simply by changing a single
std::vector<T>
到
std::vector<T,tbb::scalable_allocator<T> >
(这是切换分配器以使用 TBB 漂亮的线程私有堆的一种快速方便的方法;参见 本文档第 7 页)
(this is a quick and convenient way of switching the allocator to use TBB's nifty thread-private heaps; see page 7 in this document)
这篇关于自定义 C++ 分配器的引人入胜的例子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:自定义 C++ 分配器的引人入胜的例子?
- 从python回调到c++的选项 2022-11-16
- Stroustrup 的 Simple_window.h 2022-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- C++ 协变模板 2021-01-01
- 近似搜索的工作原理 2021-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- 静态初始化顺序失败 2022-01-01