Rob戈登的"Essential JNI: Java Native Interface“一书包含了将jstring转换为C字符串的代码示例:
const char* utf_string;
jboolean isCopy;
utf_string = env->GetStringUTFChars(str, &isCopy);
/* ... use string ... */
if (isCopy == JNI_TRUE) {
env->ReleaseStringUTFChars(str, utf_string);
}
请注意,只有当isCopy
为真时,它才会调用ReleaseStringUTFChars
。
但Java Native Interface: Programmer's Guide and Specification (替代链接:http://192.9.162.55/docs/books/jni/html/objtypes.html#5161
)一书中写道:
无论GetStringChars将*isCopy设置为JNI_TRUE还是JNI_FALSE,都必须调用ReleaseString-Chars。根据GetStringChars是否返回副本,ReleaseStringChars可以释放副本,也可以取消固定实例。
我假设这是戈登书中的一个bug是正确的吗?
https://stackoverflow.com/questions/5859673
复制相似问题