title: Marshall an array of structs
body: <p>I am calling a C++ function from C#. As arguments it receives a pointer to an array of structs.</p>
  
  <pre><code>struct A 
  {
      int data;
  }
  
  int CFunction (A* pointerToFirstElementOfArray, int NumberOfArrayElements)
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>[StructLayout(LayoutKind.Sequential), Serializable]
  class A
  {
      int data;
  }
  </code></pre>
  
  <p>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. <strong>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?</strong></p>
  
  <p>I guess I would need something similar to stackalloc, however I belive that only works for primitive types?</p>
  
  <p>Thank you for your help.</p>