7

Foreign (Function) Memory API

This chapter includes 28 problems covering the Foreign Memory API and Foreign Linker API. We’ll start with the classical approaches for calling foreign functions relying on the JNI API and the open-source JNA/JNR libraries. Next, we’ll introduce the new approach delivered under the code name Project Panama (third review in JDK 21 and final release in JDK 22 as JEP 454). We’ll dissect the most relevant APIs, such as Arena, MemorySegment, MemoryLayout, and so on. Finally, we’ll focus on the Foreign Linker API and the Jextract tool for calling foreign functions with different types of signatures, including callback functions.

By the end of this chapter, you’ll be skilled in putting JNI, JNA, JNR, and, of course, ...

Get Java Coding Problems - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.