[swift-evolution] Yet another fixed-size array spitball session
Jean-Daniel
mailing at xenonium.com
Tue May 30 16:36:21 CDT 2017
> Le 30 mai 2017 à 12:42, Charlie Monroe via swift-evolution <swift-evolution at swift.org> a écrit :
>
> 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.
Really ? Isn’t it due to the value semantic of swift arrays ?
If this is the former, its algorithm can probably be tweak to reuse the array and require less allocations.
Unless if you algorithm is eager in memory allocation/deallocation, you shouldn't get a significant difference between static array and dynamic array.
> 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 <mailto: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 <mailto:swift-evolution at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>
> _______________________________________________
> 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/54820f72/attachment.html>
More information about the swift-evolution
mailing list