自定义 C++ 分配器的引人入胜的例子?

Compelling examples of custom C++ allocators?(自定义 C++ 分配器的引人入胜的例子?)

本文介绍了自定义 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++ 分配器的引人入胜的例子?

基础教程推荐