Skip to content

Instantly share code, notes, and snippets.

@nasitra
Created October 31, 2015 02:44
Show Gist options
  • Select an option

  • Save nasitra/4e084a00f0e95051a287 to your computer and use it in GitHub Desktop.

Select an option

Save nasitra/4e084a00f0e95051a287 to your computer and use it in GitHub Desktop.
Shared buffer via JNI
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 }
};
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