2010-04-03 44 views
5

在处理小对象时,哪些分配器可用于STL。我已经尝试过使用Boost的池分配器,但没有得到性能改进(实际上,在某些情况下,性能有很大的下降)。C++符合STL的分配器

回答

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 library(和book)中的小对象分配器。

1

Microsoft Visual C++标准库实现为基于节点的容器提供了several proprietary allocators(至少在即将推出的Visual Studio 2010中)。

1

您需要一个适合您的特定需求的分配器。 STL通用分配器对于各种各样的情况是最好的,如果你想要一个新的分配器,你需要分析和理解你的特定需求。你必须更具体地说明你将要把这些物体放入什么容器。