[External] : Re: MemorySegment APIs for reading and writing strings with known lengths
Liam Miller-Cushon
cushon at google.com
Wed Nov 12 11:14:04 UTC 2025
>
> I believe what you mean here is that if I have a string, and I want to
> copy to a destination segment I could either:
>
> * if the string buffer is compatible, just bulk-copy that buffer into the
> target segment
> * if the string buffer is not compatible, encode the string _directly_
> into the target segment
>
> Correct? If so, I tend to agree this would be slightly preferrable, as
> we'd be touching things only once. And, I believe this can be also done to
> the existing setString method?
>
I think that's right, but I'd also gotten slightly confused. To try to
restate:
setString assumes \0, which I touched on in the original mail about not
being ideal if you want to write non-\0 terminated strings and the output
buffer is perfectly sized.
In the case where the bytes aren't compatible, setString currently falls
back to getBytes and then copies that into the destination segment. But I
think it could be optimized to encode directly to the output without
changing the API.
I had thought your proposal was to support the use-case of writing non-\0
terminated strings by using MS::ofString and then MS::copy, which I think
would have equivalent performance to setString for the bytes compatible
case, but might be more constrained for the case where the bytes aren't
compatible. Had I misunderstood that part?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/panama-dev/attachments/20251112/89f21660/attachment-0001.htm>
More information about the panama-dev
mailing list