I understand the copy on write when a struct or enum is large and it has to be stored in Heap via Value Witness Table. What if Struct or Enum is really small and can fit in InlineValueBuffer. When you assign that struct or enum to a different variable, it will be automatically written into a different existential container's InlineValueBuffer. In this scenario, it's not copied on write, is it copy on assign?
var s1 = SmallStruct(value: 1) //creates small object that can fit in Inline Value Buffer. var s2 = s1 //create a new existensial container for s2 with same value stored in new container's Buffer.
- Since in Swift4.2, String size is 16 bytes. Does that mean Strings are always stored in the heap even if they are smaller?
- When a struct or enum is stored in the heap, it needs only one word of the 3 words inline value buffer. Does it mean other two words are wasted memory?