If the C++ class implementing your native methods requires access to C++ instance data, perform the following:
Add a private long type variable called “data” to your Java class:
public class MyClass
{
static
{
com.sybase.jni.SystemUtil.loadLibrary("MyClass");
}
private long data;
public native void myMethod();
}
When you run jnicc, it now generates the C++ source and header files A_B_MyClassPrivateData.cpp and A_B_MyClassPrivateData.hpp.Add all private instance data to the A_B_MyClassPrivateData class. You can add any methods you want to this class.
Add a public finalize method that calls a private destroy method. The JNI compiler ensures that when the destroy method is called, the C++ instance data is deleted.
public class MyClass
{
static
{
com.sybase.jni.SystemUtil.loadLibrary("MyClass");
}
private long data;
public native void myMethod();
public void finalize()
{
destroy();
}
private native void destroy();
}
Access the instance data from your native methods using the data variable—see the sample in samples/SimpleRowSet.