<div dir="ltr">Thanks. I am convinced :)</div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Wed, Nov 12, 2025 at 3:30 PM Maurizio Cimadamore <<a href="mailto:maurizio.cimadamore@oracle.com">maurizio.cimadamore@oracle.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><u></u>
<div>
<p><br>
</p>
<div>On 12/11/2025 11:40, Liam Miller-Cushon
wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">
<div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
<p>For the non-\0 terminated strings, you have the
String-based MemorySegment::copy I described - e.g.</p>
<pre lang=""><pre role="presentation"><span role="presentation" style="padding-right:0.1px">void copy(String srcString, Charset srcCharset, int srcIndex, MemorySegment dstSegment, long dstOffset, int length);</span></pre></pre>
<p>With this, we also have two cases:</p>
<p>* if the charset is compatible with the string buffer,
we just bulk-copy the string buffer (or a portion of it)
into the dest segment<br>
* otherwise we can encode the srcString directly into
the dest segment</p>
</div>
</blockquote>
<div>Thanks! I think I'm caught up now. My misunderstanding
was whether MS::ofString was being suggested instead of and
not in addition to the bulk copy.</div>
</div>
</div>
</blockquote>
<p>Ah, gotcha.</p>
<p>I think MS::ofString is a possible add-on. To be fair, since
writing the document I think we've grown a little colder on it, as
such a view would make for a pretty big footgun, as it would allow
a native function (invoked via critical downcall handle) to
directly modify the string buffer (at least in some cases).
There's also some question about how `MemorySegment::equals`
should work in this case, as `equals` for heap segments takes into
account the identity of the underlying heap object.</p>
<p>So, if we could get there with the new `getString`/`copy` + maybe
some way to determine the length of an encoded string, I think it
would be preferrable/less risky. We could always add `ofString`
later, if we find a way to address and/or mitigate the issues
above.<br>
</p>
<p>Maurizio<br>
</p>
</div>
</blockquote></div>