2010-04-03 75 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通用分配器對於各種各樣的情況是最好的,如果你想要一個新的分配器,你需要分析和理解你的特定需求。你必須更具體地說明你將要把這些物體放入什麼容器。