title: Sending Byte[][] inbetween C++ unmanaged dll and C# managed dll
body: <p>I have an unmanaged C++ dll that exports the following methods:</p>
  
  <pre><code>ERASURE_API  void encode(unsigned char ** inp, unsigned char ** outp,
       unsigned int *block_nums, size_t num_block_nums, size_t sz);
  
  ERASURE_API void decode(unsigned char ** inp, unsigned char ** outp,
       unsigned int * index, size_t sz);
  </code></pre>
  
  <p>Size of inp and outp can be as large as 10KB, What would be the best performance way to call these methods from C# managed code?</p>
  
  <p>EDIT: I did the following implementation, and It works, but is it the most efficient way to do this.</p>
  
  <p>C++ :</p>
  
  <pre><code>ERASURE_API  void encode_w(unsigned char * inpbuf,int k, unsigned char * outpbuf,
      int nfecs, unsigned int * block_nums, size_t num_block_nums, size_t sz)
  { 
     unsigned char ** inp= new unsigned char*[k];
      for(i=0;i&lt;k;i++){
          inp[i] = inpbuf+i*sz;
      }
  
  unsigned char ** outp= new unsigned char *[nfecs];
      for(i=0;i&lt;nfecs;i++){
          outp[i] =outpbuf+i*sz;
      }
      encode(inp,outp,block_nums,num_block_nums,sz);
      delete [] inp;
      delete [] outp;
  }
  </code></pre>
  
  <p>C#: </p>
  
  <pre><code>[DllImport("erasure.dll")]
  public static extern void encode_w([In] byte[] inpbuf,int k,[Out] byte[] outpbuf,
       int nfecs, uint[] block_nums, int num_block_nums, int sz);
  </code></pre>