I am calling a C++ function from C#. As arguments it receives a pointer to an array of structs.
struct A
{
int data;
}
int CFunction (A* pointerToFirstElementOfArray, int NumberOfArrayElements)
In C# I have created the same struct (as a class) and I marshall it correctly (the first element in the array is received correctly). Here is my C# definition of the C++ struct:
[StructLayout(LayoutKind.Sequential), Serializable]
class A
{
int data;
}
The first element is read correctly so I know all the fields in the struct are marshalled correctly. The problem occurs when I try to send over an array of elements. How do I create an array of classes that will be in a single memory block (chunk), so the C++ function can increment the pointer to the array?
I guess I would need something similar to stackalloc, however I belive that only works for primitive types?
Thank you for your help.