Help me think: Is there something smart I can do t...
# getting-started
s
Help me think: Is there something smart I can do to fix this? https://github.com/Ashampoo/kim/blob/95aba62b09c628d25780fd3818c3d065d628df3d/src/[…]in/kotlin/com/ashampoo/kim/format/isobmff/ISOBMFFImageParser.kt At the moment I'm thinking about something along the lines if there is some kind of ByteArray that's just a "view" on the real ByteArray - so that the bytes don't have to be doubled. Is there such a construct? Not happy with the fix to make a copy of every byte read just in case I might need it later (and often won't). That was just my first idea how to solve this to get the code working, but it's certainly not a good solution. What would you suggest?
h
A Java
ByteBuffer
is kind of a view on a backing byte array, and it supports `mark()`/`reset()`. Not sure if it solves your problem though.
👍 1
s
I'm wondering if there is something lightweight. Something like copyOfRange() that would not copy the bytes in heap, but point to the same bytes.
I'm working all multiplatform. ByteBuffer is not available to me, but from reading the docs I'm not sure if it would help me. A reset() function would mean I need to read the bytes twice. This is also not ideal.
y
Sounds like you need either okio or kotlinx-io, both provide the same
Buffer
APIs.
s
How would I utilize these to help in this situation?
y
https://square.github.io/okio/3.x/okio/okio/okio/-buffer/copy.html This "copy" shares all the underlying byte arrays, it only creates a wrapper basically. There might be something more clever that can be done, but this at least should create a performance difference immediately
s
Ok, that's the right direction I think. Thanks.