1

I have some code Im converting from java to c++ for the sake of improving speed. Everything that Im looking at converting is matrix or vector based arithmetic and so I was wondering if when Im returning values back to Java if Im negating the benefit of all the native code by returning my values back in the form of primitive float arrays. The way everything is written in java where I have to plug the values back into require that I extract everything out of an array coming back from jni and plug it back into the individual floats. This is no problem but when its all said and done will I be killing my gained performance by extracting values and storing them in individual floats. I could go through and change everything to use arrays but for ease of programming Id rather leaving all the existing code in place where possible.

So I suppose I would like to know if you take a performance hit when you deal with extracting values from arrays coming back from JNI methods in c++ and if so what would be the extent of the hit.

James andresakis
  • 5,335
  • 9
  • 53
  • 88
  • 1
    Did you do performance testing on sample data to see if you really gained speed? – fge Dec 29 '11 at 01:52
  • Im just starting to convert some of the basic methods over to c++ that are for vector operations.....Ill post back after I get enough of them done to make a dent......also besides looking at frame rate improvement do you know what tools I could use in the android sdk or ndk to check for cycle speed and stuff like that.....Im programing using eclipse if that helps your answer. – James andresakis Dec 29 '11 at 02:23
  • Ok so far Ive replaced just three java methods with ones created in c++ where Ive used the eigen library to perform vector operations and now some of the onscreen movement of the objects that were under control of the java methods are now at least double their original speed. My main concern now isnt processing arrays back and forth but making sure I garbage collect properly on the native side.....any tips on taking out the trash so to speak on the native side in c++ with the jni? – James andresakis Dec 29 '11 at 04:30
  • If you're working with matrix and vector code, you should also take a look at RenderScript http://developer.android.com/guide/topics/renderscript/compute.html . – James Moore Jan 26 '15 at 22:15

0 Answers0