When does the copying take place for swift value types -
When does the copying take place for swift value types -
in swift, when pass value type, array function. re-create of array made function use.
however documentation @ https://developer.apple.com/library/ios/documentation/swift/conceptual/swift_programming_language/classesandstructures.html#//apple_ref/doc/uid/tp40014097-ch13-xid_134 says:
the description above refers “copying” of strings, arrays, , dictionaries. behavior see in code if re-create took place. however, swift performs actual re-create behind scenes when absolutely necessary so. swift manages value copying ensure optimal performance, , should not avoid assignment seek preempt optimization.
so mean copying takes placed when passed value type modified?
is there way demonstrate underlying behavior?
why important? if create big immutable array , want pass in function function, not want maintain making copies of it. should utilize nsarrray in case or swift array work fine long not seek manipulate passed in array?
now long not explicitly create variables in function editable using var or inout, function can not modify array anyway. still create copy? granted thread can modify original array elsewhere (only if mutable), making re-create @ moment function called necessary (but if array passed in mutable). if original array immutable , function not using var or inout, there no point in swift creating copy. right? apple mean phrase above?
i don't know if that's same every value type in swift, array
s i'm pretty sure it's copy-on-write, doesn't re-create unless modify it, , said if pass around constant don't run risk anyway.
p.s. in swift 1.2 there new apis can utilize implement copy-on-write on own value-types too
swift
Comments
Post a Comment