Get the pointer of a Java ByteBuffer though JNI

前端 未结 2 1667
独厮守ぢ
独厮守ぢ 2020-12-31 19:36

How can I get a pointer to the inner array of a Java ByteBuffer?

JNIEXPORT void JNICALL test(JNIEnv *env, jobject thiso) {
    jclass cls = env->FindClass         


        
相关标签:
2条回答
  • 2020-12-31 19:55
    void * data = env->GetDirectBufferAddress(obj);
    

    The ByteBuffer must be a direct one for this to work.

    0 讨论(0)
  • 2020-12-31 20:00

    If you're trying to return the address of the first element within m_buffer, then you can just do:

    return m_buffer;

    ..or:

    return &m_buffer[0]

    0 讨论(0)
提交回复
热议问题