<div dir="ltr">Hi Dmitri,<div><br></div><div>Thanks for the feedback! I'm glad that we could start a conversation on the lists, and happy to see people offering their unvarnished opinions.</div><div><br></div><div>I think conditional conformances upon Array<UInt8> is definitely an avenue worth exploring. I'm not sure what the performance implications are - Zach brought up use cases in which the ability for a data type to be backed by non-contiguous storage was important. More generally, I wanted to open up discussion as to what people wanted from a native Data type.</div><div><br></div><div>It seems like a DataProtocol-like protocol may be a good idea. Array<UInt8> could conform through conditional conformances to provide an implementation for people wanting a simple contiguous buffer that could be punned to an array or other linear collection, while a more robust dispatch_data_t-like conforming Swift stdlib type could be provided for more demanding use cases. This actually seems to be a good fit - if you only care about a data buffer as an arbitrary collection of bytes, the abstract protocol interface gives you flexibility, while if you have requirements that require a specific representation of data in memory you should use a concrete type.</div><div><br></div><div>Best,</div><div>Austin</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 11, 2016 at 11:01 AM, Dmitri Gribenko <span dir="ltr"><<a href="mailto:gribozavr@gmail.com" target="_blank">gribozavr@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Wed, May 11, 2016 at 2:37 AM, Austin Zheng via swift-evolution<br>
<<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br>
> Hello swift-evolution,<br>
><br>
> I've been thinking about a standard library 'Data' type for a while,<br>
> analogous to NSData in the same way Swift's Arrays and Dictionaries are<br>
> analogous to NSArrays and NSDictionaries. A first-class container for binary<br>
> data that is available to every Swift user, conforms to Swift semantics, and<br>
> is safer and easier to work with than UnsafeBufferPointer seems like a<br>
> natural fit for the standard library.<br>
<br>
</span>Hi Austin,<br>
<br>
This is an interesting territory!<br>
<br>
One thing that I would like to suggest for us to consider is<br>
justifying why Data needs to be a separate type from Array<Int8> and<br>
Array<UInt8>. We can add conditional extensions to Array of Int8 and<br>
UInt8 if we find that existing NSData/dispatch_data_t usecases need a<br>
few special APIs that won't make sense on arrays in general.<br>
<br>
For example, something that I would imagine people want to do with<br>
"data buffer" types is being able to make an unaligned or type punned<br>
load or store. For example, in Java, this is one of the primary<br>
usecases for a type similar in spirit, java.nio.ByteBuffer<br>
(<a href="https://docs.oracle.com/javase/7/docs/api/java/nio/ByteBuffer.html" rel="noreferrer" target="_blank">https://docs.oracle.com/javase/7/docs/api/java/nio/ByteBuffer.html</a>).<br>
<br>
Another usecase that is a crossover between Array and Data, allow<br>
Array to (unsafely) adopt ownership of an existing initialized unsafe<br>
buffer pointer. We had quite a few requests for this. Do you think<br>
this is an interesting usecase? Does it overlap with this discussion?<br>
<span class="HOEnZb"><font color="#888888"><br>
Dmitri<br>
<br>
--<br>
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if<br>
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <<a href="mailto:gribozavr@gmail.com">gribozavr@gmail.com</a>>*/<br>
</font></span></blockquote></div><br></div>