I am trying to access this C++ function from the C# code in my program
Tridiagonal3 (float** mat, float* diag, float* subd)
{
float a = mat[0][0], b = mat[0][1], c = mat[0][2],
d = mat[1][1], e = mat[1][2],
f = mat[2][2];
}
The call is as shown below
tred2(tensor, eigenValues, eigenVectors);
where tensor is float[,] and eigenvalues and eigenvectors are float[] arrays.
When i try doing this i get an exception
Access violation reading location 0x3f5dce99
when i try accessing
float a = mat[0][0]
What could be happening?
Tridiagonal3 (float** mat, float* diag, float* subd)mat is a double-pointer type (pointer to pointer).
In C#, float[,] is not a double-pointer. It’s just syntactic sugar for accessing a multi-dimensional array, just like you would do
mat[x + y * width]instead ofmat[y][x];In other words, you are passing a
float*to your C++ application, not afloat**.You should change the way you use
matto access elements using the manual offset, likemat[y + 2 * x]