Swift Struct's Reference Count -
i have question struct
in wwdc2016, session recommend use sturct (value type)
but if structs have 3 more inline variable words, struct must manage reference count store large value heap
then question is
when struct have 3 struct , each struct have 2 or 3 struct or value type
i want know how works whether using reference count or not in situation
below example of structs
struct viewmodel { var titlemodel: titlemodel var contentmodel: contentmodel var layoutmodel: layoutmodel } struct titlemodel { var text: string var width: float var height: float } struct contentmodel { var content: string var width: float var height: float } struct layoutmodel { var constant: float var multiply: float }
structures , enumerations have value-semantics. there no notion of reference count, because passed copying. members may pointers reference-types, pointer copied. long don't have reference-type in structure, don't need worry reference counting.
sure, 1 may argue swift internally uses copy-on-write optimizations using reference-types disguised structures (eg. array
, dictionary
etc.), implement value-semantics.
Comments
Post a Comment