Reputation: 4006
Is it possible to pass a large Structure through JNI from C to Java?
Can somebody please give me the possible solutions?
Upvotes: 2
Views: 875
Reputation: 74
Better you switch to JNA, It's much convenient way to program from C to JAVA.
Upvotes: 1
Reputation: 4455
Declare a pointer to the struct in your java class like so:
protected long ptrToX;
Next, to set it:
(*env)->GetFieldID(...)
(*env)->GetLongField(...)
(*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.
Upvotes: 3