Bastian
11/10/2021, 5:30 PMKotlinByteArray
from within my iOS app.
For that, I use KotlinByteArray.init(size:init:)
let hundredMB = 1024 * 1024 * 100
let bytes = KotlinByteArray(size: hundredMB) { _ in 5 }
For some reason, this takes about 1:20 minutes to complete and about 7 GB of RAM (iPhone Simulator).
This made me curious. Does anyone know why?
I already found the note that the init function is being called for each and every entry of the Array.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/-init-.html
But why so much memory usage? Also, NSData achieves the same in mere seconds.Paul Woitaschek
11/10/2021, 6:33 PMBastian
11/11/2021, 12:07 PMKotlinByteArray
gets initialised with all 0s.
Also, the memory seems to be freed completely when ditching the reference (which isn't the case when turning NSData
into a ByteArray
in my experience).Bastian
11/11/2021, 12:08 PMKotlinByteArray
with a custom init param from within Swift. But I guess, I will just try to be very careful about this or just try to generate sample data in different ways if I don't want to stick with 0
values.