Skip to content

Instantly share code, notes, and snippets.

@SergeyBurlaka
Last active June 11, 2020 22:32
Show Gist options
  • Save SergeyBurlaka/a3dd2adbc7a5f263988d4517387b104a to your computer and use it in GitHub Desktop.
Save SergeyBurlaka/a3dd2adbc7a5f263988d4517387b104a to your computer and use it in GitHub Desktop.
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