Andrea Giuliano
10/08/2020, 3:38 PMasad.awadia
10/08/2020, 3:42 PMAndrea Giuliano
10/08/2020, 3:43 PMZach Klippenstein (he/him) [MOD]
10/08/2020, 3:47 PMasList().subList()
daphillips
10/08/2020, 8:52 PMasList().subList()
(and `List`s in general) is boxing. I'm not sure if both of those actually box the values since they just wrap the array, but if they do there will be both a performance hit and a significant memory hit (boxed bytes are 16 times larger in memory than primitive bytes).
This of course only applies if you are memory/performance constrained and if those calls actually box the primitives.Michael de Kaste
10/09/2020, 8:43 AMtypealias PartialByteArray = Pair<IntRange, ByteArray>
fun main() {
val bytes = ByteArray(100)
val slice: PartialByteArray = 2..10 to bytes
}
and then extend the PartialByteArray with your neccesary functions if need be like so:
operator fun PartialByteArray.get(index: Int) = second[first.first + index]
operator fun PartialByteArray.set(index: Int, value: Byte) {
second[first.first + index] = value
}
operator fun PartialByteArray.iterator() = first.map(second::get)
jimn
10/09/2020, 7:20 PMByteBuffer.wrap(foo).limit(10).position(2).slice()
will emit the native code you are looking for though you don't get to use a new jvm array directly against the backing store.jimn
10/09/2020, 7:29 PM