简体   繁体   中英

How to pass a large structure through JNI from C to JAVA

Is it possible to pass a large Structure through JNI from C to Java?

Can somebody please give me the possible solutions?

Declare a pointer to the struct in your java class like so:

protected long ptrToX;

Next, to set it:

  • Get the field ID using (*env)->GetFieldID(...)
  • Get the pointer using (*env)->GetLongField(...)
  • Set the pointer using (*env)->SetLongField(...)

To get it, just follow the first two steps mentioned above.

Always remember to include a finaliser that will take care of deallocating the pointer when the object is garbage-collected. Alternatively, if you do not want to incur the performance hit incurred by using finalisers, just provide a terminate() method that deallocates the pointer.

最好您切换到JNA,这是从C到JAVA编程的便捷方法。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM