如果我有兩個Java類編譯C代碼的本地調用,並且我調用另一個類中的這些類,它會影響內存嗎?例如,我有兩個調用本機函數的A類和B類。他們建立這樣的:Java JNI調用來加載庫
public class A{
// declare the native code function - must match ndkfoo.c
static {
System.loadLibrary("ndkfoo");
}
private static native double mathMethod();
public A() {}
public double getMath() {
double dResult = 0;
dResult = mathMethod();
return dResult;
}
}
public class B{
// declare the native code function - must match ndkfoo.c
static {
System.loadLibrary("ndkfoo");
}
private static native double nonMathMethod();
public B() {}
public double getNonMath() {
double dResult = 0;
dResult = nonMathMethod();
return dResult;
}
}
C類則同時呼籲,因爲他們都做一個靜態調用加載庫將在C級是怎麼回事?或者是它最好有C級呼叫的System.loadLibrary(...?
public class C{
// declare the native code function - must match ndkfoo.c
// So is it beter to declare loadLibrary here than in each individual class?
//static {
// System.loadLibrary("ndkfoo");
//}
//
public C() {}
public static void main(String[] args) {
A a = new A();
B b = new B();
double result = a.getMath() + b.getNonMath();
}
}