Package jnr.ffi.byref
Class PointerByReference
- All Implemented Interfaces:
ByReference<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));
-
Field Summary
Fields inherited from class jnr.ffi.byref.AbstractReference
value
-
Constructor Summary
ConstructorsConstructorDescriptionCreates 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
Modifier and TypeMethodDescriptionfinal void
fromNative
(Runtime runtime, Pointer memory, long offset) Copies the java value from native memoryfinal int
nativeSize
(Runtime runtime) Gets the size of the native buffer required to store the valuefinal void
Copies the java value to native memoryMethods inherited from class jnr.ffi.byref.AbstractReference
checkNull, getValue
-
Constructor Details
-
PointerByReference
public PointerByReference()Creates a new reference to a pointer value with a null default value. -
PointerByReference
Creates a new reference to a pointer value- Parameters:
value
- the initial pointer value
-
-
Method Details
-
toNative
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
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
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
-