What is the best way to pass information from java to c++?

后端 未结 8 1752
太阳男子
太阳男子 2021-02-07 04:59

I have a java application I need to pass some info to a C++ program. It has been suggested that I use some simple socket programming to do this. Is this the best way? If not

8条回答
  •  遥遥无期
    2021-02-07 05:30

    Although an answer has been accepted, a key problem here is the semantic mismatch between the two languages: assuming you have some sort of stream connection going on, how do you efficiently interchange data?

    One solution I might recommend is Google Protocol Buffers. It doesn't solve the subprocess/JNI/socket issue, but what it does do is allow you a pretty efficient way to have a complex object structure transit over a stream protocol.

    Remember: JNI is complicated, particularly for complex object references, but it's efficient. The most important thing is to pass data over that efficient context switch properly. GPB+JNI/Sub-Process Socket allows a single context switch to pull data over, combined with efficient codec support on both sides.

提交回复
热议问题