コンパイルされたCコードへのネイティブ呼び出しを持つ2つのJavaクラスがあり、それらのクラスを別のクラスで呼び出すと、メモリに影響しますか?たとえば、クラス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();
}
}