1

I searched this question but google gave nothing. Is there any way to marshal array of arrays?

//C
typedef struct SomeStruct
{
    float matrix[7][12];
} SomeStruct;

//C#
public struct SomeStruct
{
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = ???)]
    public float[][] matrix;
}

1 Answer 1

1

You have to use a linear array in the C# code:

public struct SomeStruct
{
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 7*12)]
    public float[] matrix;
}

You'll need to convert from a 2D index to a linear index for convenience.

int LinearIndex(int i, int j)
{
    return i*12 + j;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.