Hi,
I was doing some research about Open GL for Android and came across this users question on
StackOveflow : http://stackoverflow...ndroid-graphics
In his explanation, he states : "The math engine is in C (JNI)"
I was just wondering why would this user want to use a math engine written in C through JNI and not just
implement it in Java. Also, can someone help me better understand when you would want to use JNI and how it really works?
Thanks.
Question about use of JNI
Probably because doing low level math is faster in C than in Java.
I was just wondering why would this user want to use a math engine written in C
Probably because doing low level math is faster in C than in Java.
[quote name='Millionaire' timestamp='1355654760' post='5011221']
I was just wondering why would this user want to use a math engine written in C
[/quote]
Java game developers on the desktop tend to use Java directly for their math stuff. But the Dalvik VM on Android is not as performant as the Oracle VM or OpenJDK on the desktop. So time critical routines are often split off into C.
Runtime efficiency aside, it (generally) takes a lot less development time to use existing code than it does to write new code. If an entire system has already been implemented in C it would almost certainly be faster to use that than it would to re-write the entire thing in Java.
Just so you guys know, but Android has a per-process limit of 16-24 megabytes of RAM usage. Try not to get over that limit. If you are going to call JNI functions often and allocate/free memory on each call, you'd need to keep JNI initialized as malloc-ing and free-ing is expensive, I found that out the hard way.
And if you need to update Java from the JNI side, you'd need to free the local reference.
And if you need to update Java from the JNI side, you'd need to free the local reference.
Probably because doing low level math is faster in C than in Java.
[quote name='Millionaire' timestamp='1355654760' post='5011221']
I was just wondering why would this user want to use a math engine written in C
[/quote]
as a rule of thumb that isn't the case, there are only 2 really important exceptions, SIMD and trigonometry(in some ranges) on x86 (trig on other platforms perform equally).
it is very important to always make a high level interface for the JNI code since the overhead of JNI is fairly high. (if you do single operations through JNI you will almost always lose performance)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement