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. The application needs to send full images (about 300 MB currently) to the service. The images are floating point data.
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 high overheads. I have been told that JNI overheads prevent using this technique because of the cost of accessing the data from the Java service. Is this correct? Is there another way to do this without incurring high overheads?
For example, can the Java service allocate the data as a ByteBuffer and then let the native service access it through a pointer?
thanks