Official JNI API does specify if the copy is made while creating a jstring
from const char *
. Here is the quote:
NewStringUTF
jstring NewStringUTF(JNIEnv *env, const char *bytes);
Constructs a new
java.lang.String
object from an array of characters in modified UTF-8 encoding.
Does it mean the copy of const char *
is made or I have to strdup
it by myself?
NewStringUTF
creates a new String object in Java Heap. The string is backed by a byte[]
or char[]
array in Java Heap, and it does not share any off-heap data you pass in.
So, you don't need strdup
, the contents will be copied (and possibly converted) to Java Heap anyway.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.