Loading topic
Arena type appears in every example, but only as the thing that hands out memory. Arenas get their own chapter.4 min readMemorySegment, and that you are comfortable with try-with-resources. It targets Java 22, where the java.lang.foreign API is final. After reading it you should be able to pick the right arena for a piece of native memory and predict what ha5 min readMemorySegment from an Arena and know that a segment is a bounded view of memory. Basic C knowledge (fixed-size integers, pointers, alignment) is also assumed.5 min readMemorySegment, Arena and ValueLayout from the earlier chapters. You should also know how C lays out structs and arrays: field order, alignment and padding.5 min readMethodHandle code, know what a shared library is, and have a JDK 22 or later. Earlier chapters showed Arena and memory segments. Here you learn how to turn a C function name into something the Linker can call.6 min readMethodHandle is, and you have a JDK 22 or later installation. You should also have seen Linker and SymbolLookup in the earlier chapters.5 min readMethodHandle that, when invoked, calls a C function. This chapter shows how to build one, how to call it correctly, and which errors to expect when the Java and C sides disagree.5 min readchar *. The FFM API has no string type. A C string is a MemorySegment that happens to hold encoded text followed by a terminator. This chapter covers both directions: giving Java strings to C, and reading strings tha6 min readLinker, SymbolLookup and FunctionDescriptor. It covers why the JDK treats some of those calls as dangerous, what happens when you call them, and how to grant or withhold permission.5 min readLinker, SymbolLookup and FunctionDescriptor, and that you know what a C errno value is. The code targets Java 22, where allocateUtf8String and getUtf8String are the method names. Java 23 and later call them allocateFrom and `get6 min readprintf and snprintf. It assumes you can already build a downcall handle with Linker, SymbolLookup and FunctionDescriptor, and that you know how to allocate native strings in an Arena. The examples are writt5 min readFunctionDescriptor and created a downcall handle. For each struct you wrote a StructLayout and computed offsets. This works, but it is repetitive, and one wrong layout or descriptor can crash the JVM. `j5 min readjava.lang.foreign is final. The code uses the Java 22 names getUtf8String and allocateUtf8String. Java 23 and later rename them to getString and allocateFrom.6 min read