Me again :-)
Ok, I've implemented heap Buffer arguments in V3. You can also do this
via a TypeMapper + ToNativeConverter.
That would be great. With this implemented, I think all the bases are
covered, namely:
- byte[] (VM pins or copies to give us a pointer)
- heap ByteBuffer (since ByteBuffer#array returns a byte[] which the VM
can pin or copy)
- direct ByteBuffer (pointer is available via a JNI call)
- float[] (VM pins or copies to give us a pointer)
- heap FloatBuffer (since FloatBuffer#array returns a float[] which the
VM can pin or copy)
- direct FloatBuffer (pointer is available via a JNI call)
AFAIK, there is no way to create nor access the pointer on a direct
FloatBuffer.
AFAIK, once you have the direct FloatBuffer as a jobject in your native
code, you can simply call GetDirectBufferAddress, just like you can on a
direct ByteBuffer.
According to the javadoc, the only way they are created is via
asFloatBuffer() on a direct ByteBuffer - and I couldn't see anyway to get
back to the direct ByteBuffer from a FloatBuffer view.
That means something like this will throw an exception:
FloatBuffer fb = ByteBuffer.allocateDirect(1024).asFloatBuffer();
some_function(fb);
Its a pretty weird corner case, and there's nothing JNA can do about it.
I'm not 100% sure if this will work, but as I mentioned in my previous mail,
if you pass any Buffer for which isDirect returns through to JNI, you should
be able to get its pointer.
Cheers,
Albert