1

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 Answers1

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);
}
technomage
  • 9,861
  • 2
  • 26
  • 40