sharing a buffer between a Java service and a native app with minimal access overhead

廉价感情. 提交于 2019-12-12 11:17:55

问题


I am trying to set up a shared memory region between an Android Java service and a native process. The native process has no Java component, is purely C++, and is invoked from the shell directly by a command line.

I believe that I can use ashmem and binder to accomplish this. First call ashmem_create_region, call mmap on the result, then pass the resulting fd to the other process using binder. The other process does mmap on the fd and thereby gains access to the shared region.

I understand that this works between two Java apps and also works between a Java app or service and a native mode process.

I am wondering now how the Java service can access the data efficiently. I want to use this mechanism to copy a buffer of floats, about 300MB in size, from the native app to the Java service. Now the Java service needs to access this data without overheads such as occurs with JNI. What is the best strategy for allocating the shared region so that the native program can do fast copy of the floats into the buffer and the Java service can access the values with minimal overhead?

thanks


回答1:


Have a look on this example. It creates a shared memory between Java and native applications. https://github.com/vecio/AndroidIPC



来源:https://stackoverflow.com/questions/17980941/sharing-a-buffer-between-a-java-service-and-a-native-app-with-minimal-access-ove

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!