IPC between Java and C++

后端 未结 3 1477
逝去的感伤
逝去的感伤 2021-02-11 10:52

My goal here is to make two separate applications (one in Java and other in C++, both on the same machine) read from the same SQLite database. The C++ implementation already wor

相关标签:
3条回答
  • 2021-02-11 11:11

    Not sure about the performance you need over the IPC but there are several approaches:

    1. use sockets
    2. use pipes
    3. use memorymappedfiles (using memorymappedfiles you will have a performance gain)

    In either case you will need a serializer/deserializer for the objects(data) you pass from java to c++ and viceversa.

    Depending on the data format you might need serializer/deserializer only on Java side. (e.g. you send out binary data that C++ will read without needing to decode it anymore). A good tutorial on how to use memorymapped file in java can be found here and in C++ you need to use mmap function.

    0 讨论(0)
  • 2021-02-11 11:24

    Actually I was wrong. I don't need to use JNI to use named pipes in Java. I have successfully communicated these two processes using basic techniques. In java I have just used FileOutputStream and FileInputStream to communicate with the named pipes.

    This link was specially useful to me:

    http://carminedimascio.com/2014/01/named-pipes-with-java/

    0 讨论(0)
  • 2021-02-11 11:31

    You could use swig. Swig can parse your C/C++ header and generate Java clases/functions of it. The generated code has jni calls to call your c++ clases or your c functions.

    0 讨论(0)
提交回复
热议问题