GCC最近发布了4.5版本,对于C++的支持除了更为丰富的0x特性支持外(参考
这里),
还增加了一个新的profile模式(尚处于试验阶段),可以根据程序运行状态给出关于STL使用的一些优化建议。
参看如下的描述:
    - 
    An experimental 
    profile mode  has been added. This is an implementation of
    many C++ standard library constructs with an additional analysis
    layer that gives performance improvement advice based on
    recognition of suboptimal usage patterns. For example,
     #include <vector>
 int main()
 {
 std::vector<int> v;
 for (int k = 0; k < 1024; ++k)
 v.insert(v.begin(), k);
 }
 
 
    When instrumented via the profile mode, can return suggestions about
    the initial size and choice of the container used as follows:
     vector-to-list: improvement = 5: call stack = 0x804842c ...
 : advice = change std::vector to std::list
 vector-size: improvement = 3: call stack = 0x804842c ...
 : advice = change initial container size from 0 to 1024
 
 
    These constructs can be substituted for the normal libstdc++
    constructs on a piecemeal basis, or all existing components can be
    transformed via the -D_GLIBCXX_PROFILEmacro.
 
 
这个profile mode的主要作用就是根据代码实际运行状况给出关于STL的使用优化建议。有点遗憾的是,该profile方法是intrusive的,必须添加-D_GLBCXX_PROFILE来重新编译所有的代码。
Profile mode的提出源于09年CGO的一篇
paper,作者里边出现了华人的名字(根据拼音来判断);作者地址填的显然是Purdue大学的:
    Dept. of Comput. Sci., Purdue Univ., West。
GCC的Profiler对C++的支持一贯停留在和C同样的水平;由于C++模板机制和OO的存在使得很多时候分析profiling结果的意义被大大削弱。
这个针对STL的profile mode还是很值得期待的。