Memory API: Patterns, Uses Cases, and Performance
summary
The Memory API (final in Java SE 22) shows concrete replacements for ByteBuffer: MemorySegments and Arenas give explicit allocation and deallocation semantics (close an arena to free all segments), preventing the unpredictable unmap/GC problem; MemoryLayout + Jextract maps C structs into Java layouts; VarHandles deliver near-unsafe speed for struct access. A demo loads 1 billion elements (ID, temperature) from a binary file—one layout scans in ~3–6s, a reorganized layout under 1s—showing fragmentation, confined vs shared arena costs, and that the approach actually works.
AI-written summary · about
chapters (12)
- 0:00Introduction to Memory API
- 12:37Goals of Panama project
- 20:55ByteBuffer API issues
- 31:59Memory Access API overview
- 48:43Arena object explained
- 1:12:48Coffee break
- 1:33:52Memory segment access patterns
- 1:57:26Memory integrity and safety
- 2:01:11Memory layout API
- 2:29:42VAR handles and VLEs
- 2:34:01Future of Memory API
- 2:38:03Q&A and conclusion
related talks
16mForeign Function and Memory API
45mProject Panama - Foreign Function & Memory API
49mWhen a Java Programmer Meets C
51mBeyond ByteBuffers
01h 01mWorking with Memory Outside the Java Heap: Is There a Future for ByteBuffer(s)?
51mNative Interoperability with JDK 25 and the FFM API
21mMemory Efficient Java
39mMemory Efficient Java
