C# P/Invoke 数组的数组
C# P/Invoke array of arrays
我搜索了这个问题,但 google 什么也没找到。
有什么方法可以编组数组吗?
//C
typedef struct SomeStruct
{
float matrix[7][12];
} SomeStruct;
//C#
public struct SomeStruct
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = ???)]
public float[][] matrix;
}
您必须在 C# 代码中使用线性数组:
public struct SomeStruct
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 7*12)]
public float[] matrix;
}
为方便起见,您需要将二维索引转换为线性索引。
int LinearIndex(int i, int j)
{
return i*12 + j;
}
我搜索了这个问题,但 google 什么也没找到。 有什么方法可以编组数组吗?
//C
typedef struct SomeStruct
{
float matrix[7][12];
} SomeStruct;
//C#
public struct SomeStruct
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = ???)]
public float[][] matrix;
}
您必须在 C# 代码中使用线性数组:
public struct SomeStruct
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 7*12)]
public float[] matrix;
}
为方便起见,您需要将二维索引转换为线性索引。
int LinearIndex(int i, int j)
{
return i*12 + j;
}