Consider a struct like System.Drawing.Point - one with LayoutKind.Sequential and containing only primitive members. I have a C# array of such structs.
I'm passing it to an (unmanaged) C++ function via P/Invoke. On the C++ side there's a corresponding definition of the struct (e.g. struct Point { int x, y; };
). The function takes a Point*
arg.
My question is, in what cases does the CLR copy the data and in what cases does it just pin it? Variables include:
- Array type: one-dimensional or rectangular
- C# definition of the function - using
Point*
orPoint[]
/Point[,]
- using
fixed(Point* pointer = array)
or not
I want to avoid the copying because it's slow.