I have allocated a 2D array of size 5000 x 4859 using new() in C++ from a file.
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;
}
Then in another function where am using mytable through a pointer.
void someFunction()
{
int ** table;
input file;
table= file.gettable();
// doing neccessary operations.
}
When I decrease the size of the table to 500 x 500, it works fine but for large size it gives an std:: bad alloc error . Where did I go wrong? Please help.