• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Native (C) code vs VM code in the book

 
andrew ennamorato
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To answer the question, it looks like there is one chapter on using C and the NDK.
 
andrew ennamorato
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interesting. Thanks for the info!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic