12 messages in net.java.dev.jna.usersRe: [jna-users] Buffer arguments as p...
FromSent OnAttachments
Albert StrasheimAug 22, 2007 3:47 pm 
Wayne MeissnerAug 22, 2007 4:19 pm 
Albert StrasheimAug 22, 2007 4:39 pm 
Wayne MeissnerAug 22, 2007 5:33 pm 
Albert StrasheimAug 22, 2007 5:47 pm 
Wayne MeissnerAug 22, 2007 6:13 pm 
Albert StrasheimAug 22, 2007 6:21 pm 
Albert StrasheimAug 22, 2007 6:26 pm 
Wayne MeissnerAug 22, 2007 8:05 pm 
Albert StrasheimAug 23, 2007 3:25 pm 
Wayne MeissnerAug 23, 2007 4:32 pm 
Albert StrasheimAug 23, 2007 4:50 pm 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [jna-users] Buffer arguments as pointer-to-bufferActions...
From:Albert Strasheim (full@gmail.com)
Date:Aug 22, 2007 6:21:10 pm
List:net.java.dev.jna.users

Hello

The best I can do is make something like this work:

interface Foo extends Library { void some_function(FloatBuffer fb); }

which would be equivalent to: interface Foo extends Library { void some_function(float[] fb); }

That _should_ pass the array directly to JNI - depending on whether the VM supports/can pin the array. If not it will copy to/from a native buffer and pass that on. If your native code depends on the address of the array not changing, that will break, but otherwise it should be fine.

Looks like it almost works. However, I don't think this check in r216 of Function is quite right:

else if (arg instanceof Buffer) { if (!(arg instanceof ByteBuffer) || !((ByteBuffer)arg).isDirect()) {

I think any direct buffer can be passed through, so it should probably simply be:

else if (arg instanceof Buffer) { if !((Buffer)arg).isDirect()) {

Also, it would be useful if I could write the function in the interface as:

void foo(Buffer buf);

and have it accept any direct buffer. Also, all the other variants should also work, e.g.,

void foo(FloatBuffer buf);

As far as I can tell, the tests don't cover these cases yet.

Thanks again for the rapid response to this feature request. :-)

Cheers,

Albert