Last active
June 11, 2020 22:32
-
-
Save SergeyBurlaka/a3dd2adbc7a5f263988d4517387b104a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/design.html | |
jdouble Java_pkg_Cls_f__ILjava_lang_String_2 ( | |
JNIEnv *env, /* interface pointer */ | |
jobject obj, /* "this" pointer */ | |
jint i, /* argument #1 */ | |
jstring s) /* argument #2 */ | |
{ | |
/* Obtain a C-copy of the Java string */ | |
const char *str = (*env)->GetStringUTFChars(env, s, 0); | |
/* process the string */ | |
... | |
/* Now we are done with str */ | |
(*env)->ReleaseStringUTFChars(env, s, str); | |
return ... | |
} | |
Global and Local References | |
The JNI divides object references used by the native code into two categories: | |
local and global references. Local references are valid for the duration of a native method call, and are automatically freed after the native method returns. Global references remain valid until they are explicitly freed. | |
The JNI functions that invoke a Java method return the result of the Java method. The programmer must call ExceptionOccurred() to check for possible exceptions that occurred during the execution of the Java method. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment