0

I'm currently using the JNI to interface with a library I built, but the library depends on the state of an object and is intended to invoke methods on the object to do work. How can I keep this object in memory without making it be global in the .cpp file interfacing the JNI?

What I would like it to look like is something like this:

public class Consumer {
    public NativeType workerObject;

    public native void methodOneToCallOnWorker();
    public native void methodTwoToCallOnWorker();
    ...
}

Is there a way to keep workerObject in state without making it global?

iHowell
  • 2,263
  • 1
  • 25
  • 49
  • 1
    Probably see https://stackoverflow.com/questions/8397426/keep-some-sort-of-c-object-alive-over-multiple-jni-calls, https://stackoverflow.com/questions/337268/what-is-the-correct-way-to-store-a-native-pointer-inside-a-java-object and https://stackoverflow.com/questions/1632367/passing-pointers-between-c-and-java-through-jni (possible duplicate?). – Radiodef Dec 21 '18 at 02:18
  • 1
    These definitely solve the problem. Thank you. – iHowell Dec 21 '18 at 02:19

0 Answers0