<div dir="ltr">Hi John Engebretson,<div>I still wonder if we can make the byte array allocator a utility to the JDK, at least an internal one. I find that besides replacing BAOS uses, it can also optimize users like InputStream.readNBytes, BufWriterImpl of classfile, and maybe many more usages. Such an internal addition may be accepted to the JDK immediately because it has no compatibility impact and does not need to undergo CSR review.</div><div><br></div><div>Chen Liang</div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Wed, Apr 9, 2025 at 11:35 AM Engebretson, John <<a href="mailto:jengebr@amazon.com">jengebr@amazon.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"><div class="msg-4194158451981981068">
<div lang="EN-US">
<div class="m_-4194158451981981068WordSection1">
<p class="MsoNormal" style="margin-left:0.5in">I think there is agreement that ByteArrayOutputStream.unsynchronized(int cap) (or some such method) would be useful. It would not require using a contiguous byte[] as the backing array so there is scope to experiment
with implementations that don't need to resize like the base BAOS does.<br>
<br>
Extending BOAS means the size is limited to an int. To go beyond would be a different API and there is lots of scope to do experiments. I think too early to create a CSR for MOS, assuming this is what you mean.<br>
<br>
<u></u><u></u></p>
<p class="MsoNormal"> Thank you Alan! PR [1] is updated with the factory method as suggested; MOS is a package-private subclass of BAOS and the Javadoc in BAOS makes no promises about the implementation returned. I allowed MOS to grow beyond 2GB and throw
an intelligent error if it cannot service a particular call (toByteArray, size, etc.). Performance is unchanged. Feedback appreciated.<u></u><u></u></p>
<p class="MsoNormal"> Thanks! <span style="font-family:"Segoe UI Emoji",sans-serif">
😊</span><u></u><u></u></p>
<p class="MsoNormal"> John<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">[1] <a href="https://github.com/openjdk/jdk/pull/24232" target="_blank">https://github.com/openjdk/jdk/pull/24232</a><u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
</div></blockquote></div>