What is the difference between allocating a multidimensional array like this
double matrix[1000][2];
or like this
unsigned int cols = 2, rows = 1000;
std::vector<double> temp(cols, 0);
std::vector<std::vector<double>> matrix(rows, temp);
In each case I can refer to elements using terms such as matrix[i][j]
I've seen both methods described on C++ tutorial pages. The first seems simpler, but I'm wondering whether there are any pitfalls that using the vector method would help me avoid.
I have a relatively small data set so am not too worried about dynamic allocation and .push_back
/ .resize
, but will be creating and abandoning data often so don't want to have any memory leak problems.