有我的代码:
import com.sun.jna.Native;
PROCESS_MEMORY_COUNTERS pmem = new PROCESS_MEMORY_COUNTERS();
boolean success = PSAPI.GetProcessMemoryInfo(kernel32.GetCurrentProcess(), pmem, pmem.size());
if (!success){
int err=Native.getLastError();
System.out.println("GetProcessMemoryInfo failed:" + err);
}
结构是 PSAPI 类:
public static class PROCESS_MEMORY_COUNTERS extends Structure {
public int cb;
public int PageFaultCount;
public int PeakWorkingSetSize;
public int WorkingSetSize;
public int QuotaPeakPagedPoolUsage;
public int QuotaPagedPoolUsage;
public int QuotaPeakNonPagedPoolUsage;
public int QuotaNonPagedPoolUsage;
public int PagefileUsage;
public int PeakPagefileUsage;
@Override
protected List getFieldOrder() {
return null;
}
}
PSAPI 类中的声明:
boolean GetProcessMemoryInfo(Pointer process, int pmem, int cb);
这段代码正确吗?
GetProcessMemoryInfo()函数需要指向pmem变量的指针,但我不知道如何在 Java 中实现这个指针:PSAPI.GetProcessMemoryInfo(kernel32.GetCurrentProcess(), pmem, pmem.size());
我希望你的帮助。谢谢!