<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div></div><div>I hear that a lot but why do all the official sources sound like copy-on-write is something you have to manually implement with a class and isUniquelyReferenced if it’s not an array or a string?</div><div><br>On May 7, 2017, at 12:02 AM, Nate Birkholz &lt;<a href="mailto:nbirkholz@gmail.com">nbirkholz@gmail.com</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><meta http-equiv="content-type" content="text/html; charset=utf-8"><div>Let me try one more time, my stupid phone keeps changing words.&nbsp;</div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature">ACTUALLY, the struct is a pointer until it's written to, and is only copied on write.<br><br>Sent from my iPhone, please excuse brevity and errors</div><div><br>On May 6, 2017, at 9:59 PM, Nate Birkholz &lt;<a href="mailto:nbirkholz@gmail.com">nbirkholz@gmail.com</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><meta http-equiv="content-type" content="text/html; charset=utf-8"><div>Oddly, until it's *written* you will be working with a pointer.<br><br>Sent from my iPhone, please excuse brevity and errors</div><div><br>On May 6, 2017, at 9:33 PM, Kelvin Ma via swift-users &lt;<a href="mailto:swift-users@swift.org">swift-users@swift.org</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr"><div><div><font face="monospace,monospace">If I have a “large” struct like<br><br>struct Vertex<br>{<br>&nbsp;&nbsp;&nbsp; let x:Double, y:Double<br>&nbsp;&nbsp;&nbsp; var r:Int, g:Int, b:Int<br>&nbsp;&nbsp;&nbsp; let s:Double, t:Double<br>&nbsp;&nbsp;&nbsp; var selected:Bool<br>}<br><br></font></div><div><font face="monospace,monospace">and I want to pass it to a function without modifying it like<br></font></div><div><font face="monospace,monospace"><br>func taxicab_distance(_ v1:Vertex, _ v2:Vertex) -&gt; Double<br>{<br>&nbsp;&nbsp;&nbsp; return v2.x - v1.x + v2.y - v1.y<br>}<br><br></font></div><div><font face="monospace,monospace">Will the entire struct Vertex get copied and pushed onto the stack, or will only the relevant members be passed to the function?<br><br></font></div><div><font face="monospace,monospace">In other words, does the compiler know to optimize this call down to<br><br></font><font face="monospace,monospace">func taxicab_distance(v2x:Double, v1x:Double, v2y:Double, v1y:Double) -&gt; Double<br>{<br>&nbsp;&nbsp;&nbsp; return v2x - v1x + v2y - v1y<br>}<br><br>?<br></font></div></div></div>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-users mailing list</span><br><span><a href="mailto:swift-users@swift.org">swift-users@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-users">https://lists.swift.org/mailman/listinfo/swift-users</a></span><br></div></blockquote></div></blockquote></div></blockquote></body></html>