Say I passed the address of the 2d array to a function along with its row and column of the 2d array.
The function will treat the address of the 2d array as 1d array. (eg. int matrix[] )
If i execute below code:
int** arr;
arr = new int*[row];
for ( int i = 0; i < row; i++ )
{
arr[i] = new int[column];
}
Hypothetically, I think in a multi-threaded system, this may not allocate contiguous memory for the 2d array. Am I correct?
However, I think in a single threaded system, this will allocate contiguous memory for the 2d array. Am I right? If so, is it "always" true? or does it depend on the compiler and the OS?
If the code is now this:
int** arr; int** arr2; arr = new int*[row]; arr2 = new int*[row]; for ( int i = 0; i < row; i++ ) { arr[i] = new int[column]; arr2[i] = new int[column]; }
I do not have contiguous memory 2d arrays. Even if the element in each row will be contiguous, the rows itself won't be contiguous with the next row. Am I correct?
If all above are correct, in C++, not every 2d array is contiguous memory, right?