0

Well, the problem is that my program crashes abruptly when trying to create a dynamic matrix of 131072*(131072*2) if I try 16384*(16384*2+2) it still works fine. So I need a way to create the matrix without the program crashing.

     int ROW=b_len;                      //131072 
  int COL=a_len+b_len+OVERFLOW;      //131072*2+2

    int** mat = new int*[ROW];
    printf("\n\nHURRA");  //It prints this
    for (int i = 0; i < ROW; ++i)  //I think it crashes here
mat[i] = new int[COL];
  printf("\n\nolv");    //But not this
Chris
  • 1
  • 1
    `std::bad_alloc` is thrown when you don't have enough memory left to allocate the required amount. 16k * 16k is about 270 million ints (~ 1 GB), which is probably fine. 131k * 131k is about 17 000 billion ints (~60 TB), which I'm sure won't fit. You'll have to find a different approach. – Etienne de Martel Apr 24 '19 at 03:06
  • 1
    Followup to @EtiennedeMartel: If you're doing math with matrices that don't fit into memory [this question](https://stackoverflow.com/questions/1380371/what-are-the-most-widely-used-c-vector-matrix-math-linear-algebra-libraries-a) has some libraries that can help with that sort of work. – Jack C. Apr 24 '19 at 03:29

0 Answers0