Package jnr.ffi.byref
Interface ByReference<T>
- All Known Implementing Classes:
AbstractNumberReference
,AbstractReference
,AddressByReference
,ByteByReference
,DoubleByReference
,FloatByReference
,IntByReference
,LongLongByReference
,NativeLongByReference
,NumberByReference
,PointerByReference
,ShortByReference
public interface ByReference<T>
A ByReference subclass is used when a primitive parameter must be passed
by-reference.
For example, the following C code,
extern void get_a(int * ap);
int foo(void) {
int 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 IntByReference ap);
}
and used like this
IntByReference ap = new IntByReference();
lib.get_a(ap);
System.out.printf("a from lib=%d\n", a.getValue());
-
Method Summary
Modifier and TypeMethodDescriptionvoid
fromNative
(Runtime runtime, Pointer memory, long offset) Copies the java value from native memorygetValue()
int
nativeSize
(Runtime runtime) Gets the size of the native buffer required to store the valuevoid
Copies the java value to native memory
-
Method Details
-
nativeSize
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
-
toNative
Copies the java value to native memory- Parameters:
runtime
- The current runtime.memory
- The native memory buffer.offset
- The offset of the field.
-
fromNative
Copies the java value from native memory- Parameters:
runtime
- The current runtime.memory
- the native memory buffer.offset
- The offset of the field.
-
getValue
T getValue()
-