本文介绍了如果GetStringUTFChars返回副本,你应该调用ReleaseStringUTFChars吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Rob Gordon的Essential JNI:Java Native Interface一书包含以下代码示例,用于将jstring转换为C字符串:

The book "Essential JNI: Java Native Interface" by Rob Gordon contains the following code example to convert a jstring to a C string:

const char* utf_string;
jboolean isCopy;
utf_string = env->GetStringUTFChars(str, &isCopy);
/* ... use string ... */
if (isCopy == JNI_TRUE) {
    env->ReleaseStringUTFChars(str, utf_string);
}

请注意,它只调用 ReleaseStringUTFChars 如果 isCopy 为真。

Note that it only calls ReleaseStringUTFChars if isCopy is true.

但书(备用链接: http://192.9.162.55/docs/books/jni/html/objtypes.html#5161 )说:

But the book Java Native Interface: Programmer's Guide and Specification (alternate link: http://192.9.162.55/docs/books/jni/html/objtypes.html#5161) says:

我认为这是戈登书中的错误是正确的吗?

I am correct in assuming this is a bug in Gordon's book?

推荐答案

是的,你的假设是正确的(你应该总是调用ReleaseStringUTFChars)。

Yes, your assumption is correct (you should always call ReleaseStringUTFChars).

这篇关于如果GetStringUTFChars返回副本,你应该调用ReleaseStringUTFChars吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 20:24