Passing Data between Java and C++ [closed]

三世轮回 提交于 2020-12-26 05:14:43

问题


I am working on developing an application in which I have an application layer in Java and one service which is nothing but a plugin in C++. I need to call native code APIs from the application layer which will be called through the JNI layer which is developed by the AOSP framework.

Now the problem is, I need to pass a chunk of data from the application layer to the native layer which will pass to the native layer through JNI calls.

Instead of passing data directly, I would like to use sharedMemory (or any efficient way). Can anyone please suggest to me that how can I pass the data from the application layer to the native code?

Is there any method available in such a way that I can allocate memory in the native layer and access that memory location from the application layer to store the data into that memory location?

I can't use the user implemented JNI layer.


回答1:


Short answer: NO.

Longer answer: You mentioned AOSP, so I assume you are working with Android OS.

The JNI implementation in AOSP is very particular, and you can communicate with it only via function arguments and primitive return values.

It is possible to create new instances of Java objects in native code using JNIEnv methods, but it is highly discouraged.

In general, the whole process of moving large amounts of data between Java and native over JNI is problematic.

Read this for more details: https://developer.android.com/training/articles/perf-jni



来源:https://stackoverflow.com/questions/65061395/passing-data-between-java-and-c

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