简体   繁体   中英

What's the difference between JNI and java wrapper for C

I'm using JNI to accelerate my program. It's like this:

JNIEXPORT void JNICALL SOME_FUNCTION(JNIEnv * jenv, jclass, jlong thiz)
{
  ...
}

Here the java program send into the c the address of the objects in the RAM, and starts the c binary.

Though I know it is really fast to execute native directly, I'm still confused at the difference between JNI and a java wrapper. Because to my understanding, the java wrapper is also working on sending in the RAM address into the C binary.

What's the intrinsic difference made them different in efficiency?

Following is an illustration that might help you answer.

By "java wrapper", I mean things like JavaCV

JNI图

JavaCV uses JNI in its implementation.

JNI is a tool that provides a C API. JavaCV is a wrapper that exposes C APIs in a Java API using JNI.

JNI allows Java code to call native code, and vice-versa.

JavaCV makes it easy to use native computer-vision libraries from Java. If you browse its source code , you can see that JNI native methods are used in its implementation.

A wrapper is a JNI interface that wraps C/C++ libraries to Java, by declaring native Java methods that calls C/C++ functions. Moreover, JNI does not start ac binary, the Java Virtual Machine is the C binary that makes native calls.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM