-
CSR
-
Resolution: Withdrawn
-
P3
-
None
-
minimal
-
This is a new feature.
-
Java API
-
SE
Summary
Provide a Record
mapper for MemorySegments
/MemoryLayout
pairs whereby given MemorySegment
instances can be projected onto new Record
instances.
Problem
There is a need to view MemorySegments
using MemoryLayouts
in a more structured way. Currently, a MemorySegment
is just a bag of bytes. Initially, it was thought a view should be a String
representation but we arrived at a better solution with a more general mapping capability.
Solution
Given a GroupLayout
, the elements in the group are matched with RecordComponent
s. This can be done for arbitrary element types of arbitrary depth. As a simple example, one can extract a Point like so:
private static final GroupLayout POINT_LAYOUT = MemoryLayout.structLayout(
JAVA_INT.withName("x"),
JAVA_INT.withName("y"));
MemorySegment segment = MemorySegment.ofArray(new int[]{3, 4});
Point point = POINT_LAYOUT.recordMapper(Point.class)
.apply(segment); // Point[x=3, y=4]
Specification
A proposed API is documented here: https://cr.openjdk.org/~pminborg/panama/21/v3/javadoc/api/java.base/java/lang/foreign/GroupLayout.html#recordMapper(java.lang.Class)
- csr of
-
JDK-8291639 Improve the ability to visualize a MemorySegment in human readable forms
-
- Closed
-