public abstract class Runtime extends Object
This class is needed by many classes to correctly initialize internal data structures, and each library loaded has its own instance of this class.
To obtain an instance of this class, use getRuntime(Object)
on a loaded library.
Example
public interface LibC {
public long write(int fd, Pointer data, long len);
}
LibC library = LibraryLoader.create(LibC.class).load("c");
byte[] bytes = "Hello, World\n".getBytes("UTF-8");
// Use the loaded library's Runtime to allocate memory for the string
jnr.ffi.Runtime runtime = jnr.ffi.Runtime.getRuntime(library);
Pointer buffer = Memory.allocateDirect(runtime, bytes.length);
// Copy the java string data to the native memory, then write the contents to STDOUT
buffer.put(0, bytes, 0, bytes.length);
library.write(1, buffer, bytes.length);
Constructor and Description |
---|
Runtime() |
Modifier and Type | Method and Description |
---|---|
abstract long |
addressMask()
Gets the address mask for this runtime
|
abstract int |
addressSize()
Gets the size of an address (e.g.
|
abstract ByteOrder |
byteOrder()
Gets the native byte order of the runtime.
|
abstract Type |
findType(NativeType type)
Looks up the runtime-specific type that corresponds to the pseudo-type
|
abstract Type |
findType(TypeAlias type)
Looks up the runtime-specific type that corresponds to the type alias
|
abstract ClosureManager |
getClosureManager()
Gets the native closure manager for this runtime
|
abstract int |
getLastError()
Gets the last native error code.
|
abstract MemoryManager |
getMemoryManager()
Gets the native memory manager for this runtime
|
static Runtime |
getRuntime(Object library)
Returns the runtime associated with the library instance.
|
static Runtime |
getSystemRuntime()
Gets the global Runtime for the current FFI provider
|
abstract boolean |
isCompatible(Runtime other)
Indicates whether this Runtime instance is compatible with another Runtime instance.
|
abstract int |
longSize()
Gets the size of a C long integer for this runtime
|
abstract <T> ObjectReferenceManager<T> |
newObjectReferenceManager()
Creates a new
ObjectReferenceManager |
abstract void |
setLastError(int error)
Sets the native error code.
|
public static Runtime getSystemRuntime()
public static Runtime getRuntime(Object library)
library
- A loaded library instance as returned from LibraryLoader.load()
public abstract Type findType(NativeType type)
type
- The native pseudo-type.Type
instance.public abstract Type findType(TypeAlias type)
type
- the type alias.Type
instancepublic abstract MemoryManager getMemoryManager()
MemoryManager
of the runtimepublic abstract ClosureManager getClosureManager()
ClosureManager
of the runtimepublic abstract <T> ObjectReferenceManager<T> newObjectReferenceManager()
ObjectReferenceManager
T
- the type parameter of the ObjectReferenceManager
.ObjectReferenceManager
public abstract int getLastError()
This returns the errno value that was set at the time of the last native function call.
public abstract void setLastError(int error)
error
- The value to set errno to.public abstract long addressMask()
public abstract int addressSize()
public abstract int longSize()
public abstract ByteOrder byteOrder()
public abstract boolean isCompatible(Runtime other)
This is not the same as calling Object.equals(java.lang.Object)
- this method only indicates whether or not artifacts from the
runtime (e.g. memory addresses) are compatible with artifacts from this one.
This is mostly for internal use.
other
- the other runtime to test for compatibilityCopyright © 2017. All rights reserved.