/** Java */
public class Memory
{
public static void main(String[] args)
{
System.out.println("Physical memory in system="+getPhysicalMemory()/1024+" kBytes");
}
public static native long getPhysicalMemory();
static
{
System.loadLibrary("Memory");
}
}
/** C++/JNI */
#include <windows.h> // windows standard include
#include "Psapi.h" // windows performance API
#include "memory.h" // JNI header file produced by JAVAH from Memory.java
/*
* Class: Memory
* Method: getPhysicalMemory
* Signature: ()J
*/
JNIEXPORT jlong JNICALL Java_Memory_getPhysicalMemory(JNIEnv * env, jclass cls)
{
PERFORMANCE_INFORMATION pi;
GetPerformanceInfo(&pi,sizeof(pi));
return pi.PhysicalTotal*pi.PageSize;
}
original url: http://forum.java.sun.com/thread.jspa?threadID=425258&tstart=255
useful link: http://java.sun.com/docs/books/tutorial/native1.1/