2011-12-15 19 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 

查看存儲的個人資料顯示正是內存被分配在哪裏,爲什麼和怎樣使用了最大部分