1

I'm porting an Linux C++ application to Android NDK and my app invokes free to the shell to see how much memory is available on the machine for logging purposes. On my android port this fails with the error:

sh: free: not found

On a Centos v4 Linux machine, I get back a result like this:

             total       used       free     shared    buffers     cached
Mem:       8308648    3904076    4404572          0     454956    1593844
-/+ buffers/cache:    1855276    6453372
Swap:      2031608        208    2031400

Is there something else I can do here to approximate this on Android?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
WilliamKF
  • 41,123
  • 68
  • 193
  • 295
  • 3
    You can get it using the answers of this question: http://stackoverflow.com/questions/3170691/how-to-get-current-memory-usage-in-android – Firefrost Apr 17 '14 at 17:09

1 Answers1

0

It seems like it should work:

StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
long bytesAvailable = (long)stat.getBlockSize() * (long)stat.getAvailableBlocks();
long megAvailable = bytesAvailable / (1024 * 1024);
Log.e("","Available MB : "+megAvailable);

Source: Android-Droid

Community
  • 1
  • 1
Wong Tan
  • 127
  • 3