H
H
hHup2018-04-13 03:19:48
Java
hHup, 2018-04-13 03:19:48

how to pass array from java to c++?

I can pass prime numbers like int , and return them back. And int[] cannot be passed to c++, the typecast error says.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2018-04-13
@TopMetaFizick

JNIEXPORT void JNICALL Java_SomeClass_someMethod(JNIEnv* env, jobject obj, jintArray array) {
    jsize size = (*env)->GetArrayLength(env, array);
    jint* buffer = (*env)->GetIntArrayElements(env, array, NULL);

    ...

    (*env)->ReleaseIntArrayElements(env, array, buffer, 0);
}

In the last parameter, it is JNI_ABORTworth passing if data from the array was needed, but the original array itself does not need to be changed. If changes to the array need to be saved, then JNI_ABORT0 must be passed instead.

P
Pavel Shvedov, 2018-04-13
@mmmaaak

Serialize the data into something language independent, like json, or some universal binary format

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question