Get Java ByteBuffer pointer though JNI

How can I get a pointer to an internal Java ByteBuffer array?

JNIEXPORT void JNICALL test(JNIEnv *env, jobject thiso) { jclass cls = env->FindClass("java/nio/ByteBuffer"); jmethodID aloc = env->GetStaticMethodID(cls, "allocateDirect", "(I)Ljava/nio/ByteBuffer;"); jobject obj = env->CallStaticObjectMethod(cls, aloc, 1000); } 

PS: I do this to separate the memory used by Java and C ++.

+7
source share
2 answers
 void * data = env->GetDirectBufferAddress(obj); 

ByteBuffer should be direct for this.

+11
source

If you are trying to return the address of the first element in m_buffer , you can simply do:

return m_buffer;

.. or:

return &m_buffer[0]

0
source

All Articles