InputStream/OutputStream concurrency guarantees

Florian Weimer fweimer at redhat.com
Wed Nov 12 16:42:26 UTC 2025


* Archie Cobbs:

> On Thu, Oct 30, 2025 at 4:39 PM Florian Weimer <fweimer at redhat.com> wrote:
>
>> I'm trying to image in a way to get rid of the double buffering in
>> FileInputStream/FileOutputStream: have the kernel access the heap
>> directly, instead of a copy.
>
> Wasn't that one of the goals of the NIO Channel API and direct
> ByteBuffers?

Code that allocates ByteBuffers cannot always determine whether they
should be direct or not.

> You've probably already considered that approach - if so I'm curious
> why it doesn't work.

It works, but if I recall there is lots of thorny code for the direct
buffer used for bouncing, to enable FileChannel etc. for heap buffers.
That could go away on platforms where the kernel can directly access
heap arrays.  But maybe that's not true on all platforms, so that code
will have to be maintained indefinitely.

Thanks,
Florian



More information about the core-libs-dev mailing list