https://kotlinlang.org logo
#language-proposals
Title
# language-proposals
b

benleggiero

07/27/2017, 12:07 PM
If you have a large array named
foo
(let's say it's 1GB) and then you say
var bar = foo
, a "copy" is made, yes. And I'm not 100% sure how, but no delay is incurred. I suspect that you get a new pointer, and any changes you make are reflected as diffs. Also,
let foo = "foo"; let bar = foo
, IIRC, makes
foo
and
bar
point to the same memory, which is safe because neither can be mutated.
v

voddan

07/27/2017, 1:01 PM
Unfortunately, there are no diffs. That would be like a Git inside an array.
Swift copies lazily. On
var bar = foo
nothing happens until you mutate
bar
. Then the whole 1GB is copied.
I admit I have a very strong negative opinion of this part of Swift. Sorry if I sound bitter
2 Views