Get all software memory modules from Android, not just the one allocated only to user processes

I have a device that I know for sure, it has 512MB RAM

Want to get this value (512 MB) programmatically.

So far, I've come across mostly these two ways on the internet:

https://stackoverflow.com/a/2159689/ ... which gives me 386MB

and also this StackOverflow question which gives 386MB too

I am assuming 386 MB is the memory available to user processes, so I would like to get all the memory or a breakdown of other processes.

+3


source to share


2 answers


I'm sure you have the same device as me: Google Nexus S (or it could be a device with a similar configuration). This phone has 512MB of physical memory, but 128 of that is taken up by the GPU. This is why there is only 384 MB available for Android and the amount the system reports. From Wikipedia entry :

The Nexus S has 512MB of RAM (Mobile DDR) (128MB is GPU assigned, leaving 384MB free for the OS)



Since all the memory available to the system (not just user processes), the value you get is correct.

+4


source


Here's a way to find out the allocated memory with the following code:



{
        Double allocated = new Double(Debug.getNativeHeapAllocatedSize())/new Double((1048576));
        Double available = new Double(Debug.getNativeHeapSize())/1048576.0;
        Double free = new Double(Debug.getNativeHeapFreeSize())/1048576.0;
        DecimalFormat df = new DecimalFormat();
        df.setMaximumFractionDigits(2);
        df.setMinimumFractionDigits(2);

        Log.d("tag", "debug.heap native: allocated " + df.format(allocated) + "MB of " + df.format(available) + "MB (" + df.format(free) + "MB free)");
        Log.d("tag", "debug.memory: allocated: " + df.format(new Double(Runtime.getRuntime().totalMemory()/1048576)) + "MB of " + df.format(new Double(Runtime.getRuntime().maxMemory()/1048576))+ "MB (" + df.format(new Double(Runtime.getRuntime().freeMemory()/1048576)) +"MB free)");

    }

      

0


source







All Articles