[Android] JNI note - How to two-way access ByteBuffer between JAVA and JNI?
Allocate memory at Java by java.nio.ByteBuffer:
Then JNI can share the same memory space with JAVA by
Reference: Java Native Interface - Accessing Array
ByteBuffer bytes = ByteBuffer.allocateDirect(size)
Then JNI can share the same memory space with JAVA by
jbyte *directBuffer = (*env)->GetDirectBufferAddress(env, byteBuffer);
jlong directBufferLength = (*env)->GetDirectBufferCapacity(env, byteBuffer);
Reference: Java Native Interface - Accessing Array
留言