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 Summary
Constructors Constructor Description PointerByReference()
Creates a new reference to a pointer value with a null default value.PointerByReference(Pointer value)
Creates a new reference to a pointer value
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
fromNative(Runtime runtime, Pointer memory, long offset)
Copies the java value from native memoryint
nativeSize(Runtime runtime)
Gets the size of the native buffer required to store the valuevoid
toNative(Runtime runtime, Pointer memory, long offset)
Copies the java value to native memory-
Methods inherited from class jnr.ffi.byref.AbstractReference
checkNull, getValue
-
-
-
-
Constructor Detail
-
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 Detail
-
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
-
-