title: How to pass C# array to C++ and return it back to C# with additional items?
body: <p>I have a C# project which is using a C++ dll. (in visual studio 2010)<br/><br/>
  I have to pass a array of int  from C# code to C++ function and C++ function will add few elements in array, when control comes back to C# code, C# code will also add elements in same array. <br/><br/>
   Initially i declared a array(of size 10000) in C# code and C++ code is able to add elements (because it was just an array of int, memory allocation is same), but the problems is i have got run time error due to accessing out side of array.<br/><br/></p>
  
  <p>I can increase size to 100000 but again i don't know how much elements C++ code will add( even it can be just 1 element). <br/><br/></p>
  
  <p>So is there a common data structure (dynamic array) exist for both or other way to do? I am using Visual studio 2010.</p>
  
  <p>Something like this i want to do. <br/>
  PS: not compiled code, and here i used char array instead of int array.</p>
  
  <p>C# code</p>
  
  <pre><code>[DllImport("example1.dll")]
  private static extern int fnCPP (StringBuilder a,int size)
  ...
  
  private void fnCSHARP(){
      StringBuilder buff = new StringBuilder(10000);
      int size=0;
      size = fnCPP (buff,size);
      int x = someCSHARP_fu();
      for ( int i=size; i &lt; x+size; i++) buff[i]='x';// possibility of run time error
  }
  </code></pre>
  
  <p>C++ code</p>
  
  <pre><code>int fnCPP (char *a,int size){
    int x = someOtherCpp_Function();
    for( int i=size; i &lt; x+size ; i++) a[ i ] = 'x'; //possibility of run time error 
    return size+x;
  }
  </code></pre>