Hello,
In my C++ to Java JNI app i need to get the value of a jstring and to keep it.
If i understood well there is two way to do this :
const jstring j_value = (jstring) penv->GetObjectArrayElement(j_arrayOfValue, i);
jboolean isCopy;
const char* str_value = penv->GetStringUTFChars(j_value, &isCopy);
...
if (isCopy) {
penv->ReleaseStringUTFChars(j_value, str_value);
}
or
const jstring j_value = (jstring) penv->GetObjectArrayElement(j_arrayOfValue, i);
int length = penv->GetStringUTFLength(j_value);
char* str_value = new char[length]; // ALLOC
penv->GetStringUTFRegion(j_value,0,length,str_value);
Since i want to keep a copy of the jstring value the second method seems more appropriate (no need for extra memcpy).
However sometimes it seems that the second method makes my app crash during the deallocation of the char buffer. Is there something special to know about GetStringUTFRegion ? Does anybody got any problems with it ?
Thank you.