std :: unordered_map分段构造函数中的故障
std::unordered_map segmentation fault in constructor
当分配以unordered_map作为atribute的对象时,我一直在遇到一个奇怪的分割错误,调试似乎指向它在分配地图时发生在Hashtable.h的某个地方。有人知道为什么会发生这种情况吗?
我在分割故障之前达到13222438的值。
struct Graph{
unordered_map<int,Graph*> neighbor;
int something(){return (int)neighbor[0]++;///so it doesnt get optimized out
}
};
int main(){
std::list<Graph*> test;
for(long long i=0; i< 100000000.0d;i++ ){
test.push_back(new Graph());
}
std::cout<< "Done" <<std::endl;
return 0;
}
当我调整您的程序实际编译并以64位模式构建时,它可以很好地完成。
当我以32位模式构建它时,它可以使用:
terminate called after throwing an instance of 'St9bad_alloc'
what(): std::bad_alloc
因为它用尽了内存。
您主要陷入系统内存限制。
在我的系统上,sizeof(Graph)
为56。仅需5 GB的内存即可创建仅对对象的100000000
。当然,还有其他与动态内存分配相关的开销和创建指针列表。
创建10000000
对象时,我能够在环境中运行该程序,比您使用的数字少10倍,但是如果我在该数字末端添加另一个零,则崩溃。
相关文章:
- "error: no matching function for call to"构造函数错误
- C++17复制构造函数,在std::unordereded_map上进行深度复制
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- 为什么在没有显式默认构造函数的情况下,将另一个结构封装在联合中作为成员的结构不能编译
- 为什么在C++中使用私有复制构造函数与删除复制构造函数
- 选择要调用的构造函数
- 如何委托派生类使用其父构造函数?
- 构造函数正在调用一个使用当前类类型的函数
- 没有用于初始化C++中的变量模板的匹配构造函数
- 初始化具有非默认构造函数的std::数组项的更好方法
- 当从函数参数中的临时值调用复制构造函数时
- 在c++构造函数中使用随机字符串生成器
- 一对向量构造函数:初始值设定项列表与显式构造
- 从构造函数抛出异常时如何克服内存泄漏
- 我不明白为什么我声明一个空的内部结构并将其传递给构造函数
- std :: unordered_map分段构造函数中的故障
- C 单链接列表复制构造函数分割故障
- 崩溃:分段故障:增强序列化加载 - 用null调用构造函数
- 复制构造函数中的SEG故障
- 未解析的外部符号突然出现.构造函数故障