sharing a buffer between a Java service and a nati

2019-06-25 05:21发布

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条回答
Summer. ? 凉城
2楼-- · 2019-06-25 06:20

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

查看更多
登录 后发表回答