1 Reply Latest reply on Sep 17, 2012 10:43 PM by EJP

    Complex Data Structures

      Another JNI novice, attempting to design an appropriate link between legacy code and a java library (Android to be more specifically, but no matter).

      Typically I have seen the majority of data exchange between C/C++ and Java occurring through primitive types and classes that access primitive types.
      I have not seen complex data structure passing between languages such as that of a Map<Object, Object> for instance.
      I'll take it, that the agreeable approach is to keep from passing complex data types, and to avoid generics. Afterall, how could one simply link an arbitrary Object in one language to one in another language without any structure to it, unless we are really just referencing and exchanging a pointer at that moment in time.

      If complex data structures exist within the C/C++, what is the basic approach for handling this issue? Break down the complex types in the native code into individual parts to be accessed and then reconstruct the data type from the basic components once again once they have been received on the java side of the library?
        • 1. Re: Complex Data Structures
          You should avoided passing complex data structure across the JNI boundary. It is slow and it is very difficult to get right. Either make your JNI code so simple that its parameters are primitives or very simple objects, or make your Java code so simple ditto.