0

I have been searching for this answer for days and can't find a straightforward answer. I am working on an application written in C++ and that has been ported to Android. I am able to launch and run without too much hassle. My task is to figure out how much RAM our app is using dynamically so that we can handle memory issues dynamically-- which in my mind means that I need to have something in my C++ that can somehow be aware of system characteristics. What I have been able to do, is in my Java code, I can pull certain metrics that belong to my app via the getMemoryInfo call. Like in this post: Programmatically find Android system info

However, I would really like to be able to probe this from our C++ code so that we can handle everything in there...

  1. Is this even possible?
  2. If it is, are the calls unrealistically expensive?
  3. If it is not, how is it possible to manage your memory through the native code rather than the Java code? i.e. If I see that I only have x amount of RAM available, I can dynamically change how much memory I want allocated to something in my C++ code to accommodate what the system has to offer.

Something along the lines of:

Ex. C++ Code:

if (android.os.thisApp.RAM left < 20 )
      allocate 10M
   else
      allocate 20M
Community
  • 1
  • 1
c alvarado
  • 69
  • 2
  • 8
  • Additional relevant link: http://stackoverflow.com/questions/2298208/how-to-discover-memory-usage-of-my-application-in-android – Morrison Chang Oct 13 '14 at 19:11
  • @MorrisonChang Thank you for the link-- I am able to do that, but in my Java code.. which is not what I want to do. What I have found so far is that I should use JNI to be able to find the RAM. I found this post http://stackoverflow.com/questions/12900695/how-to-obtain-jni-interface-pointer-jnienv-for-asynchronous-calls which does exactly what I am hoping for but I am having some serious implementation issues. Am I supposed to have a VM as well to be able to communicate? – c alvarado Oct 15 '14 at 19:52
  • I mean THIS post sorry!! http://stackoverflow.com/questions/17109284/how-to-find-memory-usage-of-my-android-application-written-c-using-ndk – c alvarado Oct 15 '14 at 19:59
  • Android's Java side is always there, even for NDK apps there is a Java wrapper, so if you can't find what you want in the JNI/NDK headers you'll have to pass that information over via JNI. – Morrison Chang Oct 15 '14 at 20:05

0 Answers0