0

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

  • "I have been told that JNI overheads prevent .. because of the cost" measure it. JNI is not slow per say and used in several places. Also http://stackoverflow.com/questions/2673839/jni-native-method-with-bytebuffer-parameter – zapl Aug 02 '13 at 17:39
  • @323go This is the same question asked by the same OP of the link you've posted. This is not "just a duplicate", it should be removed. – Richard Sitze Aug 03 '13 at 05:18
  • Welcome to Stack Overflow! Please do not re-ask the same question just because you haven't gotten an answer. On Stack Overflow, you can click the "edit" link underneath the tags to improve your question, clarify something, and/or add more information. This also "bumps" your question up to the front page, where it is more likely to be seen. Asking multiple times is strictly against the rules and will eventually lead to your being blocked from asking questions. Please read the information provided in the [help center] for more details on how the site works. – Cody Gray - on strike Aug 03 '13 at 08:45

0 Answers0