<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div></div><div>It's not just about the cost of allocation; heap accesses are incredibly slow compared to stack accesses.</div><div><br>On May 30, 2017, at 5:36 PM, Jean-Daniel via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html charset=utf-8"><br class=""><div><blockquote type="cite" class=""><div class="">Le 30 mai 2017 à 12:42, Charlie Monroe via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; a écrit :</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">There was someone a few weeks ago trying to port his Go game to Swift from (I believe) C++ and found out that the lack of fixed-size arrays was causing the move-computing algorithm to slow down significantly.<div class=""><br class=""></div><div class="">This is due to fixed arrays being able to live on stack, while "normal Array" is dynamically allocated on heap, etc.</div></div></div></blockquote><div><br class=""></div><div>Really ? Isn’t it due to the value semantic of swift arrays ?</div><div><br class=""></div><div>If this is the former, its algorithm can probably be tweak to reuse the array and require less allocations.</div><div><br class=""></div><div>Unless if you algorithm is eager in memory allocation/deallocation, you shouldn't get a significant difference between static array and dynamic array.</div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">10 000 may have been David's exageration, but imagine trying to form a chessboard using tuples - aside from the fact that you can't iterate over the tuple, the tuple type would be huge - instead of ChessPiece[8][8] (or similar syntax), you get:</div><div class=""><br class=""></div><div class="">((ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece),</div><div class="">(ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece),</div><div class="">(ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece),</div><div class="">(ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece),</div><div class="">(ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece),</div><div class="">(ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece),</div><div class="">(ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece),</div><div class="">(ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece))</div><div class=""><br class=""></div><div class="">And the practical use isn't just games - just think of any fixed-size matrices.</div><div class=""><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On May 30, 2017, at 12:25 PM, Pavol Vaskovic via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="gmail_extra"><span class="gmail-im" style="font-size:12.8px">On Tue, May 30, 2017 at 7:51 AM, David Sweeris&nbsp;<span dir="ltr" class="">&lt;<a href="mailto:davesweeris@mac.com" target="_blank" class="">davesweeris@mac.com</a>&gt;</span>&nbsp;wrote:<br class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto" class=""><span class="gmail-m_4057504060529073430gmail-"><div class=""><br class=""></div><div class="">`(Int, Int, Int, Int)` isn't *that* horrible compared to "[Int x 4]", but would you want to replace "[Int8 x 10000]" with the multipage-long tuple equivalent?</div></span></div></blockquote><div class=""><br class=""></div></span><div style="font-size:12.8px" class="">😳</div><div style="font-size:12.8px" class="">It would be really helpful to my understanding, if you spoke about a practical use case. This reads as a contrived counterexample to me…</div><div style="font-size:12.8px" class=""><br class=""></div><div style="font-size:12.8px" class="">If your type really has 10 000 values in it, why does it have to be static, why doesn't normal Array fit the bill?</div><div style="font-size:12.8px" class=""><br class=""></div><div style="font-size:12.8px" class="">--Pavol</div></div></div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class=""></div></div></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class=""></div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></body></html>