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, Project Panama to work and you’ll be able to confidently answer any interview questions with this topic on the menu.