-
Type:
Enhancement
-
Resolution: Unresolved
-
Priority:
P4
-
Affects Version/s: None
-
Component/s: core-libs
byte[] bytes = new byte[length];
MemorySegment.copy(segment, JAVA_BYTE, offset, bytes, 0, length);
return new String(bytes, charset);
However this is less efficient than what the implementation of getString does, after
It is possible that in the future C2 will be able to optimize away the copy for the known length pattern (see JDK-8364418), but it can't do that for current JDK versions, and it sounds like there are some challenges to doing that optimization.
Given all that, I think it makes sense to reconsider the possibility of adding an overload of MemorySegment#getString to read strings with known lengths, which would offer the same performance as the null-terminated getString, and avoid the copy of the byte[].
- csr for
-
JDK-8372338 Provide a MemorySegment API to read strings with known lengths
-
- Draft
-
- duplicates
-
JDK-8370882 MemorySegment support for writing strings without null terminators
-
- Closed
-
-
JDK-8370882 MemorySegment support for writing strings without null terminators
-
- Closed
-
- relates to
-
JDK-8370882 MemorySegment support for writing strings without null terminators
-
- Closed
-
-
JDK-8364418 C2 fails to optimize away an array that does not escape
-
- Open
-
-
JDK-8362893 Improve performance for MemorySegment::getString
-
- Resolved
-
-
JDK-8333843 Provide guidelines on MemorySegment to read strings with known lengths
-
- Resolved
-
- links to
-
Review(master)
openjdk/jdk/28043