TypedMemory: Typed Off‑Heap Memory Library for Java 25+
Add TypedMemory (groupId io.github.mambastudio, artifactId typedmemory, version 0.1.0) to your pom.xml and run mvn clean package to verify typed off‑heap memory usage in Java 25+ environments.
Add TypedMemory (groupId io.github.mambastudio, artifactId typedmemory, version 0.1.0) to your pom.xml, compile with Java 25, and test typed off‑heap memory allocation using Arena.ofConfined() to ensure compatibility with your native interop or data‑oriented workloads.
Summary
TypedMemory is a new Java library that provides strongly typed views over contiguous off‑heap memory, built on top of the Java Foreign Function & Memory (FFM) API. The library targets Java 25 and newer, requiring the --enable-native-access flag for modules or jars. It exposes a Mem<T> API that lets developers map Java record types to native memory, offering get(index), set(index, value), fill(value), init(lambda), copyTo, copyFrom, swap, segment, layout, size, and type methods. TypedMemory supports wrapping existing MemorySegment instances, reinterpreting memory at a given size or address, and bulk operations for fast initialization and copying. The current experimental release (0.1.0) includes typed memory allocation, record layout derivation, typed get/set access, and reinterpretation support; planned features include pointer‑typed fields and unions. The library is distributed via Maven Central with groupId io.github.mambastudio, artifactId typedmemory, and version 0.1.0, and is built with Maven compiler plugin 3.11.0 and surefire plugin 3.2.5. Developers can add the dependency to their pom.xml and use Arena.ofConfined() to allocate memory for arrays of record types. The API is designed to keep low‑level control while reducing boilerplate, making it suitable for native interop, data‑oriented programming, and high‑performance graphics workloads.
Key changes
- Introduces Mem<T> API for typed off‑heap memory allocation using Java FFM Arena
- Supports record‑based schemas, mapping Java record types to contiguous memory
- Provides get(index), set(index, value), fill(value), init(lambda), copyTo, copyFrom, swap, segment, layout, size, type methods
- Enables wrapping existing MemorySegment with Mem.wrap(recordClass, segment)
- Experimental status; may introduce breaking changes; requires Java 25+ and --enable-native-access flags
- Planned features: pointer‑typed fields, unions, support for nested structured data