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
4
  • Additional relevant link: stackoverflow.com/questions/2298208/… Commented Oct 13, 2014 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 stackoverflow.com/questions/12900695/… 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? Commented Oct 15, 2014 at 19:52
  • I mean THIS post sorry!! stackoverflow.com/questions/17109284/… Commented Oct 15, 2014 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. Commented Oct 15, 2014 at 20:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.