Reputation: 1039
I'm primarily a C++ programmer, but I'm considering using Java for a project. I will need to use some SSE intrinsics for performance reasons (these can give a huge boost in speed even relative to plain C++).
As I understand it, the way to do this in Java is to use JNI and call the SSE intrinsics in C. However, what I read in the JNI documentation unnerved me a bit, as it says that the JVM may or may not create copies of the arrays being sent to C and back.
Assuming a state-of-the-art implementation, say, OpenJDK 7, when should I actually expect copying when I request a pointer into byte[], short[], int[] or float[] ?
So far, all I found was some contradicting claims. To be accepted, an answer would have to convince me: e.g. provide evidence or cite sources rather than just express an opinion/guess.
Edit
Upvotes: 1
Views: 581
Reputation: 533660
I would consider using a direct ByteBuffer with native byte ordering. The benefit of this is it uses C space memory in a way which means you don't need to copy it to access it in Java (and visa-versa)
Upvotes: 4
Reputation: 54084
So far, all I found was some contradicting claims
No, these are not contradicting claims since what is being stated is that what you are asking is an implementation detail and depends on the JDK implementation you will use.
You should not expect the same behavior from all implementations and you should look into which one does what you want.
To give you an example of difference in implementation, the SUN
JDK passes char[]
to the C
code null terminated, while the IBM does not.
So you should be digging into the implementations and test. As far as your question, I am not sure why an array copy would not happen since I believe there is a change in the memory area entirely
Upvotes: 1