> On 15 Feb 2017, at 17:51, Daryle Walker via swift-evolution 
> <swift-evolution@swift.org> wrote:
> 
> I don't know how protocol support works. I asking because I want to maintain 
> the stride of an array being the total count times the stride of the element, 
> which would complicate nominal arrays if adding protocols to one breaks that. 

Short answer; no.

A protocol can't add stored properties, which are what determine the 
size/stride of a type; all they can add are computed properties and methods, 
neither of which are actually stored alongside the objects themselves.

Basically a type's size is memory required to store only the parts that are 
unique to that specific object (stored properties), all a protocol does is tell 
the compiler some operations you can perform, the actual code for which is 
stored elsewhere.

As Karl points out though the type's size isn't necessarily the full picture, 
as a store property can be a pointer to some other piece of memory such as an 
object (class, rather than struct) or to an unmanaged buffer and other 
constructs that are particularly useful for things like arrays.

Also, for future reference, questions like this are more appropriate to the 
swift-users mailing list; swift-evolution is intended more for language 
improvements, rather than general queries. Easy enough mistake to make though!
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to