Take the 2-minute tour ×  I need to send an array of 500,000
ints over a socket between two Android devices. Currently, I'm
spending a lot of time converting the int[] to a byte[] so that
Java's socket will accept it (see my previous question
Efficiently send large int[] over sockets in Java, where we
determined there's no faster way to do the typecasting in Java).
My question now is, if I take the int[] and pass it through JNI
to the Android NDK, can I expect the typecasting to byte[] to go
any faster in native code? I know typecasting int* to char* is
quite simple in plain-old C, however I'm wondering if the JNI
will negate any performance gains.  Furthermore, once I have a
byte[] in my native code, can I efficiently pass it back to my
Java code or do I need to implement the socket in C as well?
Edit 1: People have been posting a lot of answers without
clicking on the link. Using ByteBuffers is not a good option,
its actually way slower than mask-and-shift, which is still way
slower than my performance cr