Created
October 31, 2015 02:44
-
-
Save nasitra/4e084a00f0e95051a287 to your computer and use it in GitHub Desktop.
Shared buffer via JNI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct data { | |
| float a; | |
| float b; | |
| }; | |
| static jint com_example_test(JNIEnv *env, jobject thiz, jobject buffer) { | |
| struct data* pbuf = (data *)env->GetDirectBufferAddress(buffer); | |
| return 0; | |
| } | |
| static JNINativeMethod method_table[] = { | |
| { "native_test", "(Ljava/nio/ByteBuffer;)I", | |
| (void*)com_example_test } | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ByteBuffer buffer = ByteBuffer.allocateDirect(8); | |
| buffer.order(ByteOrder.LITTLE_ENDIAN); | |
| buffer.putFloat(0, a); | |
| buffer.putFloat(4, b); | |
| native_test(buffer); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment