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++ 分配器的引人入胜的例子?


基础教程推荐
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 这个宏可以转换成函数吗? 2022-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 常量变量在标题中不起作用 2021-01-01