Hi.
I'm currently using shared memory for IPC between Java and C++ apps, but looking for a more convenient alternative.
Can someone advice better method, but with same performance speed?
Thanks!
Hi.
I'm currently using shared memory for IPC between Java and C++ apps, but looking for a more convenient alternative.
Can someone advice better method, but with same performance speed?
Thanks!
It depends how you plan to have your apps interract. In the posix environment you have pipes, shared memory, sockets, semaphores and message queues. See this question: Comparing unix lixux IPC for more information.
What is the interaction model for your processess (i.e. client/server, producer-consumer, etc)?
From personal experience, I would suggest your best bet would be pipes (since they are just files to read and write bytes) or sockets (since both languages support them).
As mikelong said, this depends a lot on what you are doing. AFAIK, none of the IPC methods have native Java bindings, so you're probably going to have to use JNI and make bindings yourself, so all the different methods are roughly equally as hard. If you are doing message passing though, I highly suggest using message queues. They are very easy to use (once you have the bindings), and have good performance. If you need to "share" some resource, then you probably want to stick with shared memory.
As it sounds like you are having some sort client/server thing, I would say use either message queues, unix domain sockets, or named pipes. They all involve copying data in the kernel, so they are not quite as fast as shared memory, but they are still very fast. If you have message-like data (individual small packets), go with message queues. That is probably the cleanest solution. If you have more of a stream of data, use pipes or sockets. Sockets have the advantage that you can easily make it network transparent (like X11) later on if you want, but they are slightly harder to work with than pipes. The performance is probably very similar.
While likely not the most efficient, Java only supports sockets out of the box (the best I recall). They are very flexible, just perhaps not as fast as other options. As Zifre mentioned, it leaves you with an opportunity for network transparency, as well as language/binding transparency; as pretty much every language supports a socket library out of the box these days.
While I am throwing efficiency out of the window, if you wish to take it to the next level, you could probably wrap this in a Web Service of some kind. Use an embedded web server on the consumer for the producers to submit their data to.
The easiest way to communicate between applications written in different languages is IMHO CORBA. There are very good open source CORBA ORBs out there. We use TAO for C++ and JacORB for Java. There are also companies like OCI and Remedy that provide technical support.