问题
I have an array of bytes and I want to pass it to C function using JNA. However I only found examples which allocated a pointer using new Memory and used write function to copy array data but for me is not acceptable because I have big block of data.
Is there a possibility just to pass my Java array directly to c library ?
I want to do something like this :
MyLib lib = Native.loadLibrary("test");
Pointer p = myByteArray; //I want to make it possible
lib.someFunction(p);
回答1:
Passing a primitive array or a Pointer
to memory are equivalent operations, i.e. you can map like this:
public interface MyLibrary extends Library {
void someFunction(byte[] input);
void someFunction(Pointer input);
}
来源:https://stackoverflow.com/questions/18104494/jna-pointer-to-unsigned-char