Package jnr.ffi.byref

Class PointerByReference

java.lang.Object
jnr.ffi.byref.AbstractReference<Pointer>
jnr.ffi.byref.PointerByReference
All Implemented Interfaces:
ByReference<Pointer>

public final class PointerByReference extends AbstractReference<Pointer>
AddressByReference is used when the address of a pointer must be passed as a parameter to a function.

For example, the following C code,

 
 extern void get_a(void** ap);

 void* foo(void) {
     void* a;
     // pass a reference to 'a' so get_a() can fill it out
     get_a(&a);

     return a;
 }
 
 

Would be declared in java as

 
 interface Lib {
     void get_a(@Out PointerByReference ap);
 }
 
 

and used like this

 
 PointerByReference ap = new PointerByReference();
 lib.get_a(ap);
 Pointer ptr = ap.getValue();
 System.out.println("ptr from lib=" + a.getValue());
 System.out.println("ptr contents=" + ptr.getInt(0));
 
 
  • Constructor Details

    • PointerByReference

      public PointerByReference()
      Creates a new reference to a pointer value with a null default value.
    • PointerByReference

      public PointerByReference(Pointer value)
      Creates a new reference to a pointer value
      Parameters:
      value - the initial pointer value
  • Method Details

    • toNative

      public final void toNative(Runtime runtime, Pointer memory, long offset)
      Description copied from interface: ByReference
      Copies the java value to native memory
      Parameters:
      runtime - The current runtime.
      memory - The native memory buffer.
      offset - The offset of the field.
    • fromNative

      public final void fromNative(Runtime runtime, Pointer memory, long offset)
      Description copied from interface: ByReference
      Copies the java value from native memory
      Parameters:
      runtime - The current runtime.
      memory - the native memory buffer.
      offset - The offset of the field.
    • nativeSize

      public final int nativeSize(Runtime runtime)
      Description copied from interface: ByReference
      Gets the size of the native buffer required to store the value
      Parameters:
      runtime - The current runtime.
      Returns:
      the size in bytes of the native type