Thats pretty much correct. For simple (and mostly one-off) accesses,
Pointer.set{Int,Long,Float,etc} is faster than
Pointer.getByteBuffer().put{Int,Long,
etc}
However, if you need to do a lot, or bulk transfers, then getting a
ByteBuffer and using it multiple times can be faster - even faster than the
bulk transfer operations in Pointer.
One caveat to be aware of - allocating a lot of direct ByteBuffers in a loop
can be hazardous - they don't seem to get GC'd as quickly as Memory objects,
so you can end up with a huge amount of memory used by the jvm.
On 14/11/2007, Timothy Wall <twal...@dev.java.net> wrote:
On Nov 6, 2007, at 11:00 AM, James Way wrote:
I'm using jna to pass a large array of data from a database to a
fortran program. I implemented this by passing a Pointer to a java
callback function from native code, and I was wandering how fast
this was compared to jni, for instance. Also, is using
pointer.setFloat() as fast as using a pointer.getDirectByteBuffer()?
I'd recommend profiling your scenario to see what performs better.
Direct buffers have higher allocation/deallocation costs than
com.sun.jna.Memory, and native code can access either faster than a
java primitive array. Tweaking the memory from Java will probably
depend on the specific circumstances, since both methods use a
dedicated JNI call to do the write. Wayne Meissner did some
profiling in this area, but I don't recall the results.