I want to pass the base c-string to the correct Java
How do you pass a C ++ string in java? You cannot pass a C ++ bare pointer in java, you must use jni functions for this, i.e.:
jstring jstr = (*env)->NewStringUTF(env, data());
and then pass jstr to java or pass as a java array. This function duplicates the string, so there are no thread safety issues.
If you want to split the memory area between java nad C ++, you can try the following jni functions: NewDirectByteBuffer, GetDirectBufferAddress, GetDirectBufferCapacity.
source share