I need to get a pointer containing the direct memory address of a Java array, via JNI, without invoking some sort of copying (ie direct access).
GetArrayElements returns a pointer to a copied array - I need to be able to modify an int[] on the Java layer directly from a the native layer.
Casting from a jintArray to an int* returns the memory address successfully, but I'm not sure if this is particularly stable...?
Is there anything I can do here...?
解决方案
You can use an IntBuffer using direct memory (with native byte order). In JNI you can use the address as a pointer. In Java you have to use the get() and put().