I'm working on a Java application that needs to communicate with a C application. The C application uses shared memory and mmap to communicate, and I need the Java application to have access to the same memory.
My first attempt involved using JNI calls to retrieve data from the shared memory, but the overhead of each JNI call killed performance, so I'd like a way to get access to that memory in Java and do the data retrieval on the Java side.
The idea I have is that I'd need do the following:
- Use one JNI call to get the location of the shared memory location I need to attach to
- Create a new FileChannel()
- Use that FileChannel to create a MappedByteBuffer using map()
Is this the best way to do this? Also, I'm not sure how to actually create the FileChannel to point at the correct memory location.