I'm doing a matrix-product exercise (strassen's algorithm actually) using C++. Since the biggest data set given reaches 2048 * 2048, I tried to free the temp memory using delete[]. But it says there is a memory access violation in it, why?
Here are some of the code that may help:
struct Matrix {
int row, column;
int** m;
Matrix(int row, int column) {
m = new int* [2048];
for (int i = 0; i < row; i++)
m[i] = new int[2048];
}
~Matrix() {
if (m != NULL) {
for (int i = 0; i < 2048; i++) {
delete[] m[i]; //access violation happens here
}
delete[] m;
}
}
};
Matrix matAdd(Matrix matA, Matrix matB) {
Matrix matR = Matrix(matA.row, matA.column);
for (int i = 0; i < matA.row; i++)
for (int j = 0; j < matA.column; j++) {
matR.m[i][j] = matA.m[i][j] + matB.m[i][j];
}
return matR;
}
//There are some other functions below but the structure is basically the same