Let the java file is Runner.java and the code is:
public class Runner {
static {
try {
System.loadLibrary("sample
}
catch (UnsatisfiedLinkError e) {
System.err.println("Native
System.exit(1);
}
}
public static void main(String argv[]) {
//declaration of the array
byte array[] = new byte [10000];
for (int i = 0; i <>
array[i] = (byte)((int)i%64);
//call the native method
sample.point_accessPinArra
}
}
Now the input file can be like this(sample.i)
/* File : sample.i */
%module sample
%{
#include "ByteArray.h"
#include "/usr/lib/jvm/java-6-openj
JNIEXPORT void JNICALL Java_sampleJNI_point_1acce
int i;int size;
size = (*jenv)->GetArrayLength(je
//pinning process is going to be started from here if your garbage collector supports //pinning.
jbyte* body = (*jenv)->GetPrimitiveArray
(*jenv)->ReleasePrimitiveA
}
%}
%native(point_accessPinArr
Commands to compile and run:
$swig -java sample.i
$gcc -c -fpic sample_wrap.cxx -I/usr/lib/jvm/java-6-open
$gcc -shared sample_wrap.o -o libexample.so
$export LD_LIBRARY_PATH=.:$LD_LIBR
$javac Runner.java
$java Runner
No comments:
Post a Comment