title: Passing large C structure through JNI efficiently
body: <p>I have a large C structure (about 40 members, int and char[]) which I have to pass through JNI to the Java side for further processing. This happens repeatedly. (I already put the <code>GetMethodID()</code> etc. into an <code>init()</code> function on the C side so I only have to call them once.)</p>
  
  <p>What would be an efficient way to do this?</p>
  
  <p>I can think of:</p>
  
  <ol>
  <li>Instantiating a Java class with the appropriate members through <code>GetMethodID( ..., "&lt;init&gt;", ... )</code> and passing all members of the C structure through the constructor;</li>
  <li>Assigning a Java struct with the appropriate members, and initializing the (public) members through <code>SetXYZField()</code>;</li>
  <li>...</li>
  </ol>
  
  <p>Did I overlook something? (This is my first "close combat" with JNI.) Is there really no efficient way to "sync" a C structure and a Java structure?</p>
  
  <p>What is the more efficient passing method, 1. or 2.? In case of 1., should I pass constructor parameters through <code>CallXYZMethod()</code> (parameter list) or <code>CallXYZMethodA()</code> (argument array)?</p>
  
  <p>Thanks for your input.</p>
  
  <p><strong>Edit:</strong> Reworded slightly; 2. doesn't need to be a class of course, and I don't strictly need a struct on the Java side if there is some other solution to handle the C data on the Java side.</p>
  
  <p><strong>Edit 2:</strong> I do this in C++, but the struct itself stems from a C-linkage callback function, i.e. nothing C++-specific to the problem. Rephrased to read "C" instead of "C++".</p>