Free RAM: my target metric.
Java: my tool of choice.
???: a good way to get the former using the latter.
views:
126answers:
4Probably like this, using Java Native Interface (JNI) :
Kernel32 lib = (Kernel32) Native.loadLibrary ("kernel32",Kernel32.class);
Kernel32.MEMORYSTATUS mem = new Kernel32.MEMORYSTATUS ();
lib.GetMem(mem);
System.out.println ("Available physical memory " + mem.dwAvailPhys);
Difficult to do without resorting to non-portable or native libraries.
Something like
Runtime.getRuntime().freeMemory()
will only return the memory available to the JVM, which may not be the same as the system-wide available memory.
This page provides a good rundown.
http://blog.codebeach.com/2008/02/determine-available-memory-in-java.html
I know of two projects that have purchased JNIWrapper and have been happy with the result. Both Windows - based usage. When I embedded it on our current project, we wanted to know how much free ram was available when users launched our app (WebStart) since there were lots of performance complaints which were hard to investigate (we suspected RAM issues). JNIWrapper helps us to collect stats at startup about free ram, total and CPU etc so if a user group is complaining, we can check our stats to see if they have been given dodgy machines. Life saving.