Search code examples
javaperformancejava-native-interfacearraysbytebuffer

How to convert byte[] to bytebuffer native memory?


I need pass a large amount memory to jni side to parse it. I used GetByteArrayElements to get the native pointer before.but i found this method is always copy the memory,not using the memory directly. So i use GetDirectBufferAddress to get memory directly to avoid mem copy. This require that one must use allocateDirect method to allocate memory. But the memory gived to me is byte array, not native memory. Is there some way to convert byte[] to bytebuffer? Thanks.


Solution

  • Unfortunately, you will have to use put and copy your byte array to the buffer allocated with allocateDirect.