Search code examples
arraysjava-native-interfaceprimitive

JNI Set<Primitive>ArrayRegion "start" argument refers to which pointer?


Typically when I'm moving arrays in and out of JNI, I'll just copy the whole thing to and from its native counterpart, but I've encountered a situation where I need just a piece of one going to the other. When in Java land, you've got System.arraycopy(src, srcPos, dest, destPos, length). Super intuitive. But in JNI, you've just got env->Set<Primitive>ArrayRegion(array, start, length, buf). After much googling and reading several JNI references, all I get are those argument names.

Question is, does start refer to srcPos or destPos?


Solution

  • Some quick experimenting yields that the answer is destPos. You're declaring where in the Java array you'd like to begin copying. If you want a particular subsection of src, you'll have to do some pointer arithmetic to position srcPos where you'd like.