Is there a way to create a kotlinx-io `Buffer` wit...
# io
e
Is there a way to create a kotlinx-io
Buffer
with an initial size? I need to write quite some data, so an initial optimization would be good to have
f
At the moment there is no way to pre-allocate data for a buffer. In fact,
Buffer
doesn't have a fixed storage associated with it, instead, it consists of multiple small segments (8KB each, at the moment) and these segments are cached to avoid frequent allocations and reduce the latency of adding a new one to the buffer (but the cache exists only on JVM target and its size is relatively small). If you're experiencing performance issues related to how the buffer's storage is managed, feel free to file an issue (https://github.com/Kotlin/kotlinx-io/issues) and we'll see what could be done.
e
Hi Filipp, I'll write my code with the Buffer as it is now, and I'll let you know. Although to do a comparison benchmark I'll have to write my own multiplatform alternative
The protocol I'm working on writes and reads on the megabytes order, that's why I was wondering about it
f
Thanks! It's not the first time the question about transferring multi-megabyte portions of data arose, and it's something to consider for enchanting the library, but I haven't made any measurements yet to prove that the problem is actually there and larger segments (although, it sounds) would solve the issue.
gratitude thank you 1
e
Probably allowing to choose the segments size is the way to go. That seem to be the way other software does it
👍 1
As far as I recall encoding/decoding software like HandBrake let's you pick a buffer size, or a segment size. That kind of stuff deals with enormous quantity of data