Top Description Methods
jnr.ffi.byref

public Interface ByReference<T>

Known Direct Implementers
jnr.ffi.byref.AbstractNumberReference, jnr.ffi.byref.AbstractReference
Imports
jnr.ffi.Pointer, .Runtime

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 TypeMethod and Description
public void
fromNative(Runtime
The current runtime.
runtime
,
Pointer
the native memory buffer.
memory
,
long
The offset of the field.
offset
)

Copies the java value from native memory

public T
public int

Returns:

the size in bytes of the native type
nativeSize
(Runtime
The current runtime.
runtime
)

Gets the size of the native buffer required to store the value

public void
toNative(Runtime
The current runtime.
runtime
,
Pointer
The native memory buffer.
memory
,
long
The offset of the field.
offset
)

Copies the java value to native memory

Method Detail

fromNativeback to summary
public void fromNative(Runtime runtime, Pointer memory, long offset)

Copies the java value from native memory

Parameters
runtime:Runtime

The current runtime.

memory:Pointer

the native memory buffer.

offset:long

The offset of the field.

getValueback to summary
public T getValue()
nativeSizeback to summary
public int nativeSize(Runtime runtime)

Gets the size of the native buffer required to store the value

Parameters
runtime:Runtime

The current runtime.

Returns:int

the size in bytes of the native type

toNativeback to summary
public void toNative(Runtime runtime, Pointer memory, long offset)

Copies the java value to native memory

Parameters
runtime:Runtime

The current runtime.

memory:Pointer

The native memory buffer.

offset:long

The offset of the field.