While you create byte array from string you hold some memory. You can pass String directly and save memory.
Proper way of converting String (jstring in C++) to char* is:
JNIEXPORT jstring JNICALL Java_your_package_structure_className_myMethod(JNIEnv* env, jobject jobj, jstring str) {
char* native_string = env->GetStringUTFChars(env, str, JNI_FALSE);
const char* hello = "hello ";
char* hello_prefix = new char[6 + strlen(native_string)];
strcpy(hello_prefix, hello);
strcat(hello_prefix, native_string);
/*
call
env->ReleaseStringUTFChars(env, str, native_string);
if env->GetStringUTFChars(env, str, JNI_TRUE) was executed
*/
jstring result = env->NewStringUTF(env, hello_prefix);
delete[] hello_prefix;
return result;
}
const char* GetStringUTFChars(JNIEnv *env, jstring string,
jboolean *isCopy);
Returns a pointer to an array of bytes representing the string in modified UTF-8 encoding. This array is valid until it is released by ReleaseStringUTFChars().
If isCopy is not NULL, then *isCopy is set to JNI_TRUE if a copy is made; or it is set to JNI_FALSE if no copy is made.
Critical natives
While you works with primitive types, you can use fast critical natives functions to reduce overhead of java conversions. Look at this post for details.