[swift-users] Large Structs, and COW.
    Daniel Tartaglia 
    danielt1263 at gmail.com
       
    Fri Jan 22 13:22:00 CST 2016
    
    
  
If I have a large struct with lots of sub-structs and I assign to just one field of one of the sub-structs, will the system make a deep copy of the struct or a shallow copy where the unmodified portions of the object still point the same memory as the original struct?
In other words, given this code:
struct SubStruct {
    var a: Int = 0
    var b: Int = 0
}
struct VeryLarge {
    var subStructA = SubStruct()
    var subStructB = SubStruct()
    var subStructC = SubStruct()
    // lots of other stuff
}
func bar(var vl: VeryLarge) -> VeryLarge {
    vl.subStructA.a = 5
    return vl
}
let vl1 = VeryLarge()
let vl2 = bar(vl1)
Will vl2.subStructB be a copy of vl1.subStructB, or an entirely new object?
I’m worried about performance when making small changes to large objects.
Thanks,
Daniel T.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160122/5a44eebe/attachment.html>
    
    
More information about the swift-users
mailing list