3 ms·
Not true. Swift uses value semantics for structs and enums, arc for classes. The arc optimizer afaik is able to remove atomics when it can determine code is not
by zer0zzz 4y ago
Not true. Swift uses value semantics for structs and enums, arc for classes. The arc optimizer afaik is able to remove atomics when it can determine code is not used for multi threading too.
- Ygg2 4y agoThat sounds a lot like C# which uses GC everywhere except for structs. Having optional GC but integrated GC does lead to a schism in API libraries (see C#, D, etc.). From my experience it's hard to go no-GC in C# because a lot of libraries depend on GC.
- zer0zzz 4y agoYeah, same for enums in Swift. Although with classes in Swift it's not quite like a runtime GC. Static code is inserted to retain and release. Afaik the arc optimizer uses an ownership model to optimize placement of retain/releases. I have been out of C# programming for over a decade now, but in Swift most guidance actually discourage use of classes, while a lot of types in the stdlib use a "Copy on Write" pattern where a struct contains a class that acts as a backing store. This gives the type value semantics but guarantees assignments will be cheap, only when the backing data is modified and the reference count is not unique is the data copied.