在c+中创建大尺寸二维数组时出现分段错误+; 我在C++中使用了从文件中使用新()/的大小为5000×4859的二维数组。 class input { public : int **mytable; int rows; int columns; input() { rows=5008; columns=4859; std::ifstream file("test.txt"); mytable=new int *[rows]; for(int i=0;i<rows;i++) { mytable[i]=new int [columns]; } // read the input and inserted them into the array. } int ** gettable() { return mytable; }

在c+中创建大尺寸二维数组时出现分段错误+; 我在C++中使用了从文件中使用新()/的大小为5000×4859的二维数组。 class input { public : int **mytable; int rows; int columns; input() { rows=5008; columns=4859; std::ifstream file("test.txt"); mytable=new int *[rows]; for(int i=0;i<rows;i++) { mytable[i]=new int [columns]; } // read the input and inserted them into the array. } int ** gettable() { return mytable; },c++,C++,当我将表的大小减小到500x500时,它可以正常工作,但是对于较大的表,它会给出一个std::bad alloc错误。我哪里出错了?请帮助。您试图分配太多内存。请看: std::bad_alloc是分配函数作为异常抛出的对象类型,用于报告分配存储失败 显然,您超出了操作系统允许的内存限制。这应该会有所帮助,。创建阵列时可以考虑的一些相关事项。 {虽然我可以运行和使用4000×4000的数组(可能是因为系统配置),但它在40000×40000的情况下失败。}bad_alloc==您无法为回复分配更

当我将表的大小减小到500x500时,它可以正常工作,但是对于较大的表,它会给出一个std::bad alloc错误。我哪里出错了?请帮助。

您试图分配太多内存。请看:

std::bad_alloc是分配函数作为异常抛出的对象类型,用于报告分配存储失败

显然,您超出了操作系统允许的内存限制。

这应该会有所帮助,。创建阵列时可以考虑的一些相关事项。
{虽然我可以运行和使用4000×4000的数组(可能是因为系统配置),但它在40000×40000的情况下失败。}

bad_alloc==您无法为回复分配更多内存库。但是我应该如何创建这样大的2D矩阵呢?
void someFunction()
{
int ** table;
input file;
table= file.gettable();

// doing neccessary operations.

}