[External] : Re: MemorySegment APIs for reading and writing strings with known lengths

Liam Miller-Cushon cushon at google.com
Tue Nov 11 14:35:39 UTC 2025


On Tue, Nov 11, 2025 at 3:10 PM Maurizio Cimadamore <
maurizio.cimadamore at oracle.com> wrote:

> Going back to this... do you have a use case where you would like to
> know the byte length of a string encoded in a given charset?
>

The main use-case is to know if a preexisting buffer is big enough to write
out an encoded string to.

As well, for the protobuf example, it's writing a varint length as a prefix
before the string data, so it needs to know what the encoded length is to
know how many bytes to reserve to encode the length itself.

(I'm happy to separate out the discussion of
string.getBytesLength(Charset), or not, if you think it could safely be
pursued separately without risk of dead ends. I mentioned it here because
the use-case is at least somewhat related, and in case you saw connections
I'd missed.)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/panama-dev/attachments/20251111/ee7a4e1e/attachment.htm>


More information about the panama-dev mailing list