C++ STL符合要求的分配器

5

在处理小对象时,有哪些可用于STL的分配器。我已经尝试使用来自Boost的池分配器进行测试,但没有性能提升(实际上,在某些情况下,性能还会明显下降)。

3个回答

3

你没有说明使用的编译器,但它可能已经预装了一堆分配器。这是在Mac上使用gcc 4.2.1时的情况:

~$ find /usr/include/c++/4.2.1/ -name "*allocator*"
/usr/include/c++/4.2.1/bits/allocator.h
/usr/include/c++/4.2.1/ext/array_allocator.h
/usr/include/c++/4.2.1/ext/bitmap_allocator.h
/usr/include/c++/4.2.1/ext/debug_allocator.h
/usr/include/c++/4.2.1/ext/malloc_allocator.h
/usr/include/c++/4.2.1/ext/mt_allocator.h
/usr/include/c++/4.2.1/ext/new_allocator.h
/usr/include/c++/4.2.1/ext/pool_allocator.h
/usr/include/c++/4.2.1/ext/throw_allocator.h

这里还有一个链接到BitMagic项目页面,介绍如何构建自己的项目。同时,请查看Loki库中的小对象分配器(以及书籍)。


1

微软的Visual C++标准库实现为基于节点的容器提供了几个专有分配器(至少在即将发布的Visual Studio 2010中如此)。


1
你需要一个适合你特定需求的分配器。STL通用分配器是最适合于各种情况的,如果你想要一个新的分配器,你需要对你的具体需求进行分析和理解。你需要更具体地说明你将把这些对象放在哪个容器中。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接