Hi,
i need your help concerning JNI performance. I am currently designing an API for my engine and i am wondering
what are the best choices for using JNI especially for efficiency and performance reasons. I want to pass values to a
c++ function using JNI. In this example i have 4 float values.
Now the question is , what will be faster and more efficient, passing four single floats or a direct FloatBuffer of size 4. Usually
the FloatBuffer should have better performance, but i have a function call overhead with 7 or more calls
Here is an example of the two solutions
Solution 1)
public native void setColor(float r, float g, float b, float a);
Solution 2)
public void setColor(float r, float g, float b, float a){
floatBuffer.clear();
floatBuffer.put®.put(g).put(b).put(a);
floatBuffer.flip();
setColor(floatBuffer);
}
public native void setColor(FloatBuffer buf);
Now is the question, is solution 2 faster than solution 1. I don’t know what the performance difference is between passing 4 float values through JNI
and passing a FloatBuffer including 7 function calls. The function calls are clear , 4x put(), flip and the call to the native method. I don’t know if the function
call overhead in solution 2 is nullifying the performance gain using a direct FloatBuffer or if it is still better than passing 4 single floats.
Can someone please tell me, if solution is still faster and more efficient than using solution 1 or does it not matter which solution i use.
i really would appreciate some help,
thanks
Mike