我使用std::unordered_map<void *, size_t>
來保存一些值,並在添加新值時收到「向量下標超出範圍」。我使用Visual Studio 2012和錯誤跟蹤是:std :: unordered_map向量下標超出範圍
std::vector<std::_List_unchecked_iterator<std::_List_val<std::_List_simple_types<std::pair<void * const,unsigned int> > > >,std::_Wrap_alloc<std::allocator<std::_List_unchecked_iterator<std::_List_val<std::_List_simple_types<std::pair<void * const,unsigned int> > > > > > >::operator[](unsigned int _Pos) Line 1140 C++
std::_Hash<std::_Umap_traits<void *,unsigned int,std::_Uhash_compare<void *,std::hash<void *>,std::equal_to<void *> >,std::allocator<std::pair<void * const,unsigned int> >,0> >::_Vec_lo(unsigned int _Bucket) Line 907 C++
std::_Hash<std::_Umap_traits<void *,unsigned int,std::_Uhash_compare<void *,std::hash<void *>,std::equal_to<void *> >,std::allocator<std::pair<void * const,unsigned int> >,0> >::_End(unsigned int _Bucket) Line 936 C++
std::_Hash<std::_Umap_traits<void *,unsigned int,std::_Uhash_compare<void *,std::hash<void *>,std::equal_to<void *> >,std::allocator<std::pair<void * const,unsigned int> >,0> >::_Insert<std::pair<void * const,unsigned int>,std::_Nil>(std::pair<void * const,unsigned int> && _Val, std::_Nil _Pnode) Line 872 C++
std::_Hash<std::_Umap_traits<void *,unsigned int,std::_Uhash_compare<void *,std::hash<void *>,std::equal_to<void *> >,std::allocator<std::pair<void * const,unsigned int> >,0> >::insert(std::pair<void * const,unsigned int> && _Val) Line 371 C++
specificaly:
_Unchecked_iterator& _Vec_lo(size_type _Bucket)
{ // return reference to begin() for _Bucket
return (_Vec[2 * _Bucket]);
}
其中_Vec是空載體和_Bucket是指針散列(> 0)。當鍵類型不是void *時,同樣的事情發生,但是uintptr_t。這是VS錯誤還是我做錯了什麼?
注:這個問題是有關c++ unorderedmap vector subscript out of range - 這是同樣的問題,但答案是沒有關係的
那麼,實際上試圖向該地圖添加內容的代碼在哪裏? – Chad 2013-04-11 19:35:39
void * ScalableMemoryManager :: allocateAligned(size_t size,size_t alignment) void * pointer = scalable_aligned_malloc(size,alignment); if(pointer == nullptr) throw bad_alloc(); mTotalAllocated + = size; mSizes.insert(SizeMap :: value_type(pointer,size)); ++ mTotalAllocations; 返回指針; }' – krojew 2013-04-11 19:37:26
是否有'mSizes'全局或靜態類成員? – 2013-04-11 19:38:59