RFR: 8369564: Provide a MemorySegment API to read strings with known lengths [v5]

Liam Miller-Cushon cushon at openjdk.org
Mon Nov 17 15:34:39 UTC 2025


On Mon, 3 Nov 2025 17:58:15 GMT, Liam Miller-Cushon <cushon at openjdk.org> wrote:

>>> > A user can easily convert between one or the other length representation by multiplying/dividing by the right scalar
>>> 
>>> That is true of e.g. UTF-16 but not of UTF-8, since the encoding is variable width and doing the conversion from bytes to characters is more expensive there.
>> 
>> Sorry, I don't mean 'character' but 'code unit'. For instance, when reading a UTF-8 string, the unit would be one byte, for UTF-16 it would be two, for UTF-32 four. So a user would just need to divide by the unit size, at least that's the idea.
>
>> I can start a thread discussing the use-case here at a higher level.
> 
> Done: https://mail.openjdk.org/pipermail/panama-dev/2025-November/021182.html

There was some discussion in [this panama-dev@ thread](https://mail.openjdk.org/pipermail/panama-dev/2025-November/021193.html), and mcimadamore wrote a document: [Pulling the (foreign) string](https://cr.openjdk.org/~mcimadamore/panama/strings_ffm.html)

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/28043#discussion_r2534538276


More information about the core-libs-dev mailing list