I'm trying to create dummy data with `KotlinByteAr...
# multiplatform
b
I'm trying to create dummy data with
KotlinByteArray
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.
p
What if you omit the optional initializer?
b
Then it also works "instantly", only taking up around 100 MiB more than the normal app's footprint. The
KotlinByteArray
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).
I was actually curious about the actual reasons behind the performance of initialising
KotlinByteArray
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.