how to access c++ memory mapped files in java
-
28-09-2019 - |
문제
I have a windows c++ application that creates a memory mapped file for a bitmap that is updated frequently. I would like to access to this memory mapped file to display the live image in a java application. How can I do that?
I know that FileChannel can be mapped to memory but I cannot see how to access a memory mapped file created by another process.
I already use JNA in my java application, should I use it to access standard windows memory mapped files functionality?
Or do you have any other solution than the memory mapped file to display a live image stream in java from an image created by a separate program?
다른 팁
There is a code sample here that does what you want using JNI to bridge from C++ (Win32 memory mapped files) to Java. Might just work as is, although some cleanup for security and threading might be needed depending on your scenario.
A memory mapped file is still a file. You could read it with java.io, or you could use a MappedByteBuffer from java.nio if you want it memory-mapped in Java too.