Foreign Function and Memory API
Java 16 also introduced a new Foreign Function and Memory API that enables Java programs to interoperate with native code and perform low-level memory operations. This feature is designed to improve the performance and interoperability of Java applications.
Example:
try (var lib = LibraryLoader.load("mylib")) {
FunctionDescriptor function = FunctionDescriptor.of(C_LONG, C_LONG, C_LONG);
FunctionHandle handle = lib.lookup("my_function", function);
int result = (int) handle.invoke(1, 2);
System.out.println(result);
}
No comments:
Post a Comment