2011-12-15 69 views
0

我的程序处理包含更新的消息。每条消息可以有多个更新。 我正在使用boost无序映射来存储要在其上完成处理的更新标识和相应对象。使用增强无序映射时的分配器异常

我这样做。

unorderedUpdateMap[updateID] = processObject; 

通常程序工作正常。但是,在负载较重的情况下(当有大量更新时),该列表可能会增长到一个很大的值,并且该进程因以下核心转储而崩溃。

(gdb) bt 
#0 0x00007fcbf562b678 in (anonymous namespace)::cpp_alloc(unsigned long, bool)() from /opt/gts/3pp/usr/lib64/libtcmalloc_minimal.so.0 
#1 0x00007fcbf5635218 in tc_new() from /opt/gts/3pp/usr/lib64/libtcmalloc_minimal.so.0 
#2 0x00007fcbeb7bee14 in __gnu_cxx::new_allocator<boost::unordered_detail::hash_node<std::allocator<std::pair<long const, mds::InstrumentData*> >, boost::unordered_detail::ungrouped> >::allocate 
    (this=0x472d3b0, __n=1) at /usr/lib/gcc/x86_64-redhat-linux6E/4.4.0/../../../../include/c++/4.4.0/ext/new_allocator.h:89 
#3 0x00007fcbeb7bd191 in boost::unordered_detail::hash_node_constructor<std::allocator<std::pair<long const, mds::InstrumentData*> >, boost::unordered_detail::ungrouped>::construct_preamble (
    this=0x53c67f90) 
    at /usr/include/boost/unordered/detail/util.hpp:319 
#4 0x00007fcbeb7bb2d9 in boost::unordered_detail::hash_node_constructor<std::allocator<std::pair<long const, mds::InstrumentData*> >, boost::unordered_detail::ungrouped>::construct_pair<long, mds::InstrumentData*> (this=0x53c67f90, [email protected]) 
    at /usr/include/boost/unordered/detail/util.hpp:267 
#5 0x00007fcbeb7b9497 in boost::unordered_detail::hash_unique_table<boost::unordered_detail::map<long, boost::hash<long>, std::equal_to<long>, std::allocator<std::pair<long const, mds::InstrumentData*> > > >::operator[] (this=0x472d3a0, [email protected]) 
    at /usr/include/boost/unordered/detail/unique.hpp:203 
#6 0x00007fcbeb7b787f in boost::unordered_map<long, ProcessObject*, boost::hash<long>, std::equal_to<long>, std::allocator<std::pair<long const, ProcessObject*> > >::operator[] (
    this=0x472d3a0, [email protected]) 

如果我去进一步分配器源(如堆栈跟踪建议)

// NB: __n is permitted to be 0. The C++ standard says nothing 
    // about what the return value is when __n == 0. 
    pointer 
    allocate(size_type __n, const void* = 0) 
    { 
    if (__builtin_expect(__n > this->max_size(), false)) 
     std::__throw_bad_alloc(); 
    return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp))); (The line which was resonpsible for crash) 
    } 

我没有在地图中使用任何自定义的分配器。但是,我们的程序与tcmalloc软件包链接。 这是一个内存问题吗?我是否需要做一些预先分配以便为这种情况做好准备

+0

越清楚你的问题是,更多的机会,你有获得很好的答案 – Mansuro 2011-12-15 10:21:02

回答

0

看起来你只是内存不足而已。

内存分配似乎失败。这可能是由于内存不足或内存泄漏。

我建议

valgrind ./mytestprogram 

获得这些信息。

您还可以使用

valgrind --tool=massif ./mytestprogram 
ms_print massif* | less -SR 

查看存储的个人资料显示正是内存被分配在哪里,为什么和怎样使用了最大部分