我正在尝试从我程序中的 C# 代码访问此 C++ 函数
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];
}
调用如下图
tred2(tensor, eigenValues, eigenVectors);
其中张量是float[,]
,特征值和特征向量是float[]
数组。
当我尝试这样做时出现异常
Access violation reading location 0x3f5dce99
当我尝试访问
float a = mat[0][0]
会发生什么?
最佳答案
Tridiagonal3 (float** mat, float* diag, float* subd)
mat是双指针类型(pointer to pointer)。
在 C# 中,float[,] 不是双指针。它只是访问多维数组的语法糖,就像您使用 mat[x + y * width]
而不是 mat[y][x]
一样;
换句话说,您正在将 float*
传递给您的 C++ 应用程序,而不是 float**
。
您应该更改使用mat
的方式,以使用手动 偏移访问元素,例如mat[y + 2 * x]
关于c# - 导入 C++ dll 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6033783/