问题描述
放弃 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++ 分配器的引人入胜的例子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!