Instead of using an array, you can use the direct ByteBuffer.allocateDirect () buffer. It has an address in the field, and this address does not change for the life of the ByteBuffer. Direct ByteBuffer uses minimal heap space. You can get the address using reflection.
You can use Unsafe to get the address, the problem is that the GC can move it at any time. Objects are not fixed in memory.
In JNI, you can use special methods to copy data to / from Java objects to avoid this problem (and others). I suggest you use them if you want to exchange data between objects with code C.
source share