1 Reply Latest reply: Apr 15, 2012 9:35 PM by 930794 RSS

    Pointer-to-Pointer in JNI

    930794
      Hi,

      How would I create a Java JNI function that links to a C function with a pointer-to-pointer parameter? For example,C function is void func(void **data);

      Also, is there a command or setting that stops the JVM from moving memory? So that I could avoid pass the first element of an array/ptr and use indexing rather than copy the entire array/data from Java to C.

      Thanks
      David
        • 1. Re: Pointer-to-Pointer in JNI
          EJP
          How would I create a Java JNI function that links to a C function with a pointer-to-pointer parameter? For example,C function is void func(void **data);
          public class Holder<T>
          {
            private T value;
          
            public T get() { return value; }
            public void set(T value) { this.value = value; }
          }
          
            // JNI method
             private native void func(Holder<YourValueType> holder);
            // The JNI method must declare its own void *data and set it to the value in the holder parameter;
            // call your C func(&data);
            // then set the value of 'data' back into the holder value.
          Also, is there a command or setting that stops the JVM from moving memory? So that I could avoid pass the first element of an array/ptr and use indexing rather than copy the entire array/data from Java to C.
          Get/ReleasePrimitiveArrayCritical(), but do study all the caveats in that documentation carefully.