C++ std::string 队列通过 JNI 需要共享内存吗?
我试图了解从我编写的 Java 供 UI 使用的 C++ 守护程序获取字符串的机制是什么。我将发布一张我设想的图片,然后继续提问:
有两个问题我在这里设想:
1)信号量需要可供库使用。在 Windows 中,这可以通过命名信号量并访问其句柄来完成。在 Linux 中,我被指出在共享内存中使用信号量,并通过共享内存的密钥让进程了解它。这对我来说很模糊,但是这个概念可以同步 Java 和守护进程吗?
2)我是否必须将队列放置在共享内存中才能使上图中的 ???
链接正常工作?队列可以并且应该驻留在 .so 中吗?
这些是我的担忧。我愿意并欢迎任何和所有的帮助、挑战和理智的恳求,并将尽我所能提供所有额外必要的信息。提前致谢。
I'm trying to understand what the mechanism is for getting a string from a c++ daemon I've written to Java for use by a UI. I'll post a picture of what I envision, then continue the question afterward:
There are two issues that I envision here:
1) The semaphore needs to be available to the library. In Windows, that could've been done with a named semaphore and access to it's handle. In Linux, I've been pointed toward using a semaphore in shared memory and making processes aware of it through a key to the shared memory. It's vague to me, but will that concept work to synchronize Java and the daemon?
2) Do I have to place the queue in shared memory in order to make the ???
link in the above chart work? Can and should the queue reside in the .so?
So those are my concerns. I'd love and welcome any and all help, challenges, and pleas for sanity and will do my best to provide all additionally necessary information. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在单独的进程中运行这两个应用程序,在普通 Linux 中,这意味着您无法直接通过内存在这些进程之间进行通信。 Java VM是一个进程,C++守护进程也是一个进程。它位于单独的内存位置,顺便说一句,这些位置由内存管理器 (MMU) 进行加扰。所以没有办法获得内存访问。
如果您愿意,可以谷歌“内部进程通信”。我更喜欢使用套接字对来运行双向父子通信。
You're running both applications in a separate process, in vanilla Linux this means you cannot communicate between these processes via memory directly. The Java VM is a process, and the C++ daemon is a process. It's in separate memory locations which are btw scrambled by the Memory Manager (MMU). So there is no way of getting memory access.
Google on "inner process communication" if you'd like. I prefer to run with socketpair for bi-directional parent-child communication.