I don't understand, why you don't care the memory ...
# io
i
I don't understand, why you don't care the memory pressure, and what will happened once the
byteCount
large than
Int.MAX_VALUE
? The code from Kotlinx.io The second important, how to do zero-copy? Of course I can't access the internal data structure of the Buffer.
Copy code
override fun write(
        source: Buffer,
        byteCount: Long
    ) {
        require(byteCount >= 0L) { "byteCount: $byteCount" }
        require(source.size >= byteCount) { "source.size=${source.size} < byteCount=$byteCount" }
        check(!closed) { "closed" }

        val allContent = source.readByteArray(byteCount.toInt())
        // Copy bytes from that segment into the file.
        val bytesWritten = allContent.usePinned { pinned ->
            variantFwrite(pinned.addressOf(0), byteCount.toUInt(), file).toLong()
        }
        if (bytesWritten < byteCount) {
            throwIOExceptionForErrno("file write")
        }
    }
j
That code predates
UnsafeBufferOperations
. There hasn't really been focus on improving the file API since then.
❤️ 1