Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JNA direct vs interface mapping?

Tags:

jna

Sorry, this maybe a basic question. What are the difference between JNA direct mapping and interface mapping?

Is my interpretation correct:

  • Direct mapping: use the library object directly (like static main in Java)

  • Interface mapping: create an instance of the library object.

Thanks in advance!

like image 881
RockTheStar Avatar asked Jun 27 '16 22:06

RockTheStar


1 Answers

Direct mapping directly binds your Java methods (declared with the native modifier) to native code which attempts to use the call stack as-is. Direct mapping is most effective if you restrict your function arguments and return values to primitive types (the Pointer type may be considered primitive).

The interface mapping uses a Proxy and dynamically translates Java function signatures into a generic native entry point with a list of arguments which must subsequently be translated into native primitives. It's more flexible w/r/t translating Java types to and from native, but can be much slower due to the runtime translation of arguments.

like image 82
technomage Avatar answered Oct 19 '22 06:10

technomage