Jump to content

View more

Image of the Day

Boxes as reward for our ranking mode. ヾ(☆▽☆)
#indiedev #gamedev #gameart #screenshotsaturday https://t.co/ALF1InmM7K
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Question about use of JNI

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
6 replies to this topic

#1 Millionaire   Members   

117
Like
0Likes
Like

Posted 16 December 2012 - 04:46 AM

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.

Edited by Millionaire, 16 December 2012 - 04:53 AM.


#2 J. Evola's Apprentice   Members   

307
Like
2Likes
Like

Posted 16 December 2012 - 05:11 AM

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.

#3 Aldacron   GDNet+   

4488
Like
3Likes
Like

Posted 16 December 2012 - 05:46 AM

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.


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.

#4 jbadams   Senior Staff   

25490
Like
2Likes
Like

Posted 16 December 2012 - 06:33 AM

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.

- Jason Astle-Adams


#5 farmdve   Members   

194
Like
1Likes
Like

Posted 16 December 2012 - 11:13 AM

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.

#6 SimonForsman   Members   

7633
Like
1Likes
Like

Posted 16 December 2012 - 01:25 PM

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.


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)

Edited by SimonForsman, 16 December 2012 - 01:35 PM.

I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

#7 Millionaire   Members   

117
Like
0Likes
Like

Posted 16 December 2012 - 09:25 PM

Thanks everyone, this really clears up some questions. :)




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.