title: SWIG Efficiency of carrays.i vs arrays_java.i when you need/have data as native java array anyway
body: <p>I'm curious about what it says in the swig <a href="http://www.swig.org/Doc2.0/SWIGDocumentation.html#Java_c_arrays" rel="nofollow">docs</a> regarding efficiency of the 2 fundamental ways of dealing with arrays in swig/java. In particular, I'm wondering if the carrays.i way is really more efficient if you end up needing to copy to/from a native java array anyway?  E.g. say I have a C func void populate(int x[]) to call and then I needed to pass the result to a Java func that takes a native java int[].  To do it the carrays way, I'd need to:</p>
  
  <pre><code>%include "carrays.i"
  %array_class(int, intArray);
  
  intArray array = new intArray(10000000);
  populate(array);
  </code></pre>
  
  <p>then copy to a native java array:</p>
  
  <pre><code>int[] nativeArray = new int[10000000];
  for(int i = 0; i &lt; 10000000; ++i)
  {
      nativeArray[i] = array.getitem(i);
  } 
  </code></pre>
  
  <p>then call my native java function which takes a native int[]</p>
  
  <pre><code>f(nativeArray);
  </code></pre>
  
  <p>Is that really more efficient than</p>
  
  <pre><code>%include "arrays_java.i"
  int[] nativeArray = new int[10000000];
  populate(nativeArray);
  f(nativeArray);
  </code></pre>
  
  <p>since in the former case, you have to do the copy anyway?</p>