开发者

Quick C++ data to Java transfer

I'm trying to transfer a stream of strings from my C++ program to my Java program in an efficient manner but I'm not sure how to do this. Can anyone post up links/explain the basic idea about how do implement this?

I was thinking of writing my data into a text file and then reading the text file from my Java program but I'开发者_C百科m not sure that this will be fast enough. I need it so that a single string can be transferred in 16ms so that we can get around 60 data strings to the C++ program in a second.


Text files can easily be written to and read from upwards with 60 strings worth of content in merely a few milliseconds.

Some alternatives, if you find that you are running into timing troubles anyway:

Use socket programming. http://beej.us/guide/bgnet/output/html/multipage/index.html. Sockets should easily be fast enough.

There are other alternatives, such as the tibco messaging service, which will be an order of magnitude faster than what you need: http://www.tibco.com/

Another alternative would be to use a mysql table to pass the data, and potentially just set an environment variable in order to indicate the table should be queried for the most recent entries.

Or I suppose you could just use an environment variable itself to convey all of the info -- 60 strings isn't very much.

The first two options are the more respectable solutions though.


Serialization: protobuf or s11n


Pretty much any way you do this will be this fast. A file is likely to be the slowest and it could be around 10ms total!. A Socket will be similar if you have to create a new connection as well (its the connect, not the data which will take most time) Using a socket has the advantage of the sender and receiver knowing how much data has been produced. If you use a file instead, you need another way to say, the file is complete now, you should read it. e.g. a socket ;)

If the C++ and Java are in the same process, you can use a ByteBuffer to wrap a C array and import into Java in around 1 micro-second.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜