Swift Struct Storage
We can see that it’s exactly as we expected: when passing the
structto aninoutparameter, thestructis laid out contiguously in memory and then a pointer to it is passed in.[…]
structstorage in Swift is ultimately pretty straightforward, and much of what we’ve seen carries over from C’s much simplerstructs. Astructinstance is largely treated as a loose collection of independent values, which can be manipulated collectively when required. Localstructvariables might be stored on the stack or the individual pieces might be stored in registers, depending on the size of thestruct, the register usage of the rest of the code, and the whims of the compiler. Smallstructs are passed and returned in registers, while largerstructs are passed and returned by reference.structs get copied whenever they’re passed and returned. Although you can usestructs to implement copy-on-write data types, the base language construct is copied eagerly and more or less blindly.