How to pass C structs back and forth to Java code in JNI?

后端 未结 4 1942
一向
一向 2020-11-27 10:58

I\'ve got some C functions which I am calling through JNI which take a pointer to a structure, and some other functions which will allocate/free a pointer to the same type o

4条回答
  •  借酒劲吻你
    2020-11-27 11:37

    C structure is the collection of variables (some are function pointer). Pass to java is not a good idea. In general, it is the problem how to pass more complex type to java, like pointer.

    In JNI book, to keep the pointer/structure in native and export manipulation to java is recommended. You can read some useful articles. The JavaTM Native Interface Programmer's Guide and Specification, I have read. 9.5 Peer Classes have a solution to deal with it.

提交回复
热议问题