I'm porting a large mathematical modelling library, written in C (
not C++) to Android. Its main test harness on UNIX and Windows platforms is a command-line program, and I'm intending to build that as a command-line tool and run it in the ADB shell. This is much easier than making a normal Android app out of it. There will be an Android-specific test app as well, of course.
My command line tool needs to find out how much memory is available for its use. As it isn't a conventional app, it has no way to receive the normal memory low warnings for GUI apps. As the devices that it runs on are dedicated to doing testing, and are locked away in a server room to keep them away from prying fingers, I don't need to worry about changes in available memory as other apps are started and shut down. So it looked as if I could use classic UNIX sconf() to find out how much memory is available.
For the total physical memory of the machine, this works: sconf( _SC_PAGE_SIZE) * sysconf( _SC_PHYS_PAGES) gives me a figure that matches /proc/meminfo's MemTotal figure.
For available memory, sysconf( _SC_PAGE_SIZE) * sysconf( _SC_AVPHYS_PAGES) gives me the same size as the /proc/meminfo's MemFree figure. But that's quite small, about 200MB on a 4GB device with no apps active on the GUI.
This seems odd: is there no Linux system call that could be used to implement these sysconf queries? Is there a proper way of getting a size equivalent to MemAvailable?
Thanks,
John