Sharing a buffer between a Java service and a native application with minimal access costs

I am trying to set up a shared memory area between an Android Java service and a native process. The native process does not have a Java component, it is purely C ++ and is called from the command line directly using the command line.

I believe that for this I can use an ashtray and a binder. First call ashmem_create_region, call mmap on the result, then pass the resulting fd to another process using a binder. Another process does mmap on fd and thereby accesses the common area.

I understand that this works between two Java applications, and also works between a Java application or service and a process in native mode.

Now I am wondering how a Java service can access data efficiently. I want to use this mechanism to copy a floating point buffer of about 300 MB in size from my own application to a Java service. Now the Java service needs to access this data without overhead, for example, with JNI. What is the best strategy for distributing a common region so that a native program can quickly copy floats to a buffer and a Java service can access values ​​with minimal overhead?

thanks

+4
source share
1 answer

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

0
source

Source: https://habr.com/ru/post/1494583/


All Articles