Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8333843

Provide guidelines on MemorySegment to read strings with known lengths

XMLWordPrintable

      ADDITIONAL SYSTEM INFORMATION :
      I'm using JDK 22

      A DESCRIPTION OF THE PROBLEM :
      There is no "java.lang.foreign" subcomponent on the bug report site, FYI, but that's where this belongs.

      MemorySegment provides some very helpful get/setString methods to write strings to memory. However, they write null-terminated strings and rely on the terminator to find the length when reading. I am writing and reading strings I know the length of, and thus would like to avoid the overhead of searching for the terminator. Even with the heuristics in StringSupport it's still a mostly linear operation, which for long strings can be painful.

      It's quite trivial to implement using StringSupport's copyBytes method, however StringSupport is internal (i.e. requires --add-exports) so it would be nice to have a public way of doing this.


            pminborg Per-Ake Minborg
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: