[swift-evolution] Yet another fixed-size array spitball session

Charlie Monroe charlie at charliemonroe.net
Tue May 30 05:42:42 CDT 2017


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.

This is due to fixed arrays being able to live on stack, while "normal Array" is dynamically allocated on heap, etc.

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:

((ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece),
(ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece),
(ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece),
(ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece),
(ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece),
(ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece),
(ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece),
(ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece, ChessPiece))

And the practical use isn't just games - just think of any fixed-size matrices.

> On May 30, 2017, at 12:25 PM, Pavol Vaskovic via swift-evolution <swift-evolution at swift.org> wrote:
> 
> On Tue, May 30, 2017 at 7:51 AM, David Sweeris <davesweeris at mac.com <mailto:davesweeris at mac.com>> wrote:
> 
> `(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?
> 
> 😳
> It would be really helpful to my understanding, if you spoke about a practical use case. This reads as a contrived counterexample to me…
> 
> 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?
> 
> --Pavol
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170530/401ac4a0/attachment.html>


More information about the swift-evolution mailing list