Using GetDirectBufferAddress from JNI

前端 未结 1 365
借酒劲吻你
借酒劲吻你 2020-12-19 06:21

I am trying to understand how to use GetDirectBufferAddress from the JNI layer. To understand I\'ve build a very simple example:



        
相关标签:
1条回答
  • 2020-12-19 06:59

    What I missed from the documentation is that by default java.nio.ByteBuffer is actually using BIG_ENDIAN byte order. Which explains the behavior I was seeing on my LITTLE_ENDIAN system. See ref here.

    My code now reads as:

    image_info_bb = java.nio.ByteBuffer.allocateDirect( 5 * 4 );
    image_info_bb.order( java.nio.ByteOrder.LITTLE_ENDIAN );
    

    It appears that by default it is always BIG_ENDIAN, and no effort has been made so far to provide an API for LITTLE_ENDIAN, as explained in the bug report here (JDK-5043362 : (bf) NewDirectByteBuffer always has order ByteOrder.BIG_ENDIAN).


    Documentation has been updated recently to reflect that:

    • JDK-8225152 : Release Note: JNI NewDirectByteBuffer Creates Direct Buffer That Is java.nio.ByteOrder.BIG_ENDIAN
    0 讨论(0)
提交回复
热议问题