Hacker News new | ask | show | jobs
by throwawayninja 1541 days ago
JNI => "I write C code & after compilation java can access it as com.package.ClassName"

JNA => "I write java code & load libsomething at runtime, asking for FuncName(int, int) which java can then call into native code."

You want JNA for your use case.

1 comments

So what is the difference between this and JNA? I assume it's not the same since it's taking a while to be added to the language
JNI is the only escape hatch in the JRE. JNA leverages JNI and so has a better API while still keeping the terrible performance. This is like JNA, but more robust, and while also being an escape hatch of its own so that you can finally get performance similar to P/Invoke when making native calls.
This is apparently focused on efficiently accessing off-heap memory. In Jni lot of things require copies. Only JNI API that's reliably copy-free is ByteBuffer API.