Library for fast mapping of Java records to native memory

· systems design · Source ↗

TLDR

  • TypedMemory is a Java 25 library wrapping the FFM API to map record types onto typed off-heap memory with a minimal, Arena-based API.

Key Takeaways

  • Uses Java ClassFile API (Java 25+) to derive MemoryLayout from record components automatically, eliminating manual offset management.
  • Core API: Mem.of(MyRecord.class, arena, count) with get, set, fill, init, copyTo, swap, and layout introspection via mem.layout().
  • Supports nested structured records and fixed-size array fields via @size annotation; union types not yet supported.
  • Requires --enable-native-access JVM flag; available on Maven Central as io.github.mambastudio:typedmemory:0.1.0.
  • Experimental/v0.1.0: API may break; benchmarks pending; carrier class support and pointer-typed fields planned.

Hacker News Comment Review

  • The core tension identified: get/set still allocate Java heap objects for record instances, partially negating the off-heap advantage in zero-allocation hot paths.

Original | Discuss on HN