I'm trying to rewrite my code using dynamic memory allocation, and I'm using, amongst others, this question (and answers) to help me. So following Johanes Shaub's advice, I've declared my 2d array as:
double (*q_1_matrix)[TIME] = new double[SPACE][TIME];
When I run my code now everything seems to work fine. But when I add the following line to deallocate the memory again:
for(i = 0; i < SPACE; ++i) {
delete [] q_1_matrix[i];
}
delete [] q_1_matrix;
then I get the warning: deleting array ‘*(q_1_matrix + ((sizetype)(((long unsigned int)i) * 800ul)))’ [enabled by default] delete [] q_1_matrix[i]; and subsequently I get a Segmentation fault (core dumped).
Anybody knows what I'm doing wrong?