Re: Shared memory IPC using NIO memory-mapped files -- anyone done this?
Randall R Schulz <[email protected]>
| Newsgroups | gmane.comp.windows.devel.java.advanced |
|---|---|
| Message-ID | <[email protected]> |
On Saturday 18 August 2007 08:05, Brian Maso wrote: > Java NIO supports memory-mapped files, which has the cool ability to > allow multiple apps to share the same array of data if they all map > the same file in to their respective address spaces. > > I've wondered about using memory-mapped files for inter-process > communication for a while. Someone I know is asking me whether or not > this is good to use for high-performance communication between Java > and C++ -- basically sharing fixed-length records between Java and a > C/C++ program in a producer/consumer sort of system. > > It seems like memory-mapped files would be ideal for sharing data > like this. A Java app could extract data from some source and put it > in to a MappedByteBuffer, which would immediately be visible to any > other app on the same box that has mapped the same file. However, I > can't figure out how the Java process would "signal" the external > app, indicating that a new record is available for consumption, or > alternatively how an external app would signal the Java app to tell > it to write out a new record to the shared memory space. > > Anyone familiar with shared memory inter-process communication out > there who can give me a hint? Google and the regular sources aren't > revealing anything to me this morning. In the classic Unix (and Linux) IPC mechanisms, there's a trio of functionalities: - Shared Memory Segments - Message Queues - Semaphores Once upon a time long ago I needed to implement the shared access and locking semantics dictated by the Microsoft SMB protocol in a Unix file server whose design used a separate user-level process for each attached client PC. The design we chose was to maintain the open file and locking tables were in shared memory and use semaphores to synchronize access to those shared data structures. It turned out to work quite well. Of course, to replicate this in Java, you'd need to write JNI code (assuming no has done so already) to access the native semaphores. > Brian Maso Randall Schulz =================================== This list is hosted by DevelopMentor® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com