aspose file tools*
The moose likes Android and the fly likes Native (C) code vs VM code in the book Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Android
Bookmark "Native (C) code vs VM code in the book" Watch "Native (C) code vs VM code in the book" New topic
Author

Native (C) code vs VM code in the book

andrew ennamorato
Ranch Hand

Joined: Oct 03, 2007
Posts: 100
Poor title, so I'll try to explain:

I see the table of contents mentions image processing with C libs. How much of this (what I call native code) approach is in the book? Just a chapter or two?
Seems, of course, like you'd want to stick with I-wont-call-it-Java-so-Oracle-doesnt-sue-me VM based code just to make life easier, but curious about how/why you'd want to dip into C code and how well that works, etc. That's great that there is at least a bit of that in the book!

robi sen
author
Ranch Hand

Joined: Jan 25, 2011
Posts: 33
Great question. I would first have you look at http://developer.android.com/sdk/ndk/overview.html and read the section “When to Develop in Native Code.“ In general it is best to go to the NDK when you perhaps want to use something in C or C++ that already exists and you cannot either port it to Java because of time, complexity, or licensing issues. For example one of our clients recently had us integrated a C based DRM system from a large company. That company does not allow you to make change to the DRM system and you essentially have to use their compiled code as is (although they allow cross-compiling and give you the source). So in this case there were real legal/business requirements that forced the use of the C code. In some other cases, such as image processing, image detection, or some other CPU intensive task that does not use a huge amount of memory C might make sense. Furthermore since, in those areas, there is such a wealth of C code that is very well written it would be ease to reuse some C projects and thus those would be good candidates as well. In general though you want to stay away from the NDK unless you have a real need for it.
Augusto Sellhorn
Ranch Hand

Joined: May 24, 2007
Posts: 57
Robi;

Doesn't Dalvik have an equivalent to the JSE VM to hotspot or even a more simplistic JIT for those use cases?
robi sen
author
Ranch Hand

Joined: Jan 25, 2011
Posts: 33
Augusto,

Yes and thats why I emphasize things like reusing code for various reasons. NDK rarely will increase performance. In some rare cases it might.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41863
    
  63
To answer the question, it looks like there is one chapter on using C and the NDK.


Ping & DNS - my free Android networking tools app
andrew ennamorato
Ranch Hand

Joined: Oct 03, 2007
Posts: 100
Interesting. Thanks for the info!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Native (C) code vs VM code in the book