<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Aug 19, 2017 at 8:52 PM, Andrew Trick <span dir="ltr">&lt;<a href="mailto:atrick@apple.com" target="_blank">atrick@apple.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="overflow-wrap: break-word;"><span class="gmail-"><div><blockquote type="cite"><div><div class="gmail_extra" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="overflow-wrap: break-word;"><span><div><blockquote type="cite"><div><div class="gmail_quote" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div><br></div><div>The problem is I would expect to be able to safely call deinitialize() and friends after calling initialize(from:). If Element is a class type and initialize doesn’t fill the entire buffer range, calling deinitialize() will crash. That being said, since copy(from:bytes:) and copyBytes(from:) don’t do any initialization and have no direct counterparts in UnsafeMutableBufferPointer, it’s okay if they have different behavior than the other methods.</div></div></div></blockquote><br></div></span><div><div>You astutely pointed out that the UnsafeMutableBufferPointer.dei<wbr>nitialize() method is dangerous, and I asked you to add a warning to its comments. However, given the danger, I think we need to justify adding the method to begin with. Are there real use cases that greatly benefit from it?</div></div></div></blockquote></div></div><div class="gmail_extra" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div class="gmail_extra" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">I agree that’s a problem, which is why i was iffy on supporting partial initialization to begin with. The use case is for things like growing collections where you have to periodically move to larger storage. However, deinitialize is no more dangerous than moveInitialize, assign(repeating:count:), or moveAssign; they all deinitialize at least one entire buffer. If deinitialize is to be omitted, so must a majority of the unsafe pointer API.</div></div></blockquote></div><br></span><div><div>Here&#39;s an alternative. Impose the precondition(source.count == self.count) to the following UnsafeMutableBufferPointer convenience methods that you propose adding:</div><div><br></div><div>+++ func assign(from:<wbr>UnsafeBufferPointer&lt;Element&gt;)</div><div>+++ func assign(from:<wbr>UnsafeMutableBufferPointer&lt;<wbr>Element&gt;)</div><div>+++ func moveAssign(from:<wbr>UnsafeMutableBufferPointer&lt;<wbr>Element&gt;)</div><div>+++ func moveInitialize(from:<wbr>UnsafeMutableBufferPointer&lt;<wbr>Element&gt;)</div><div>+++ func initialize(from:<wbr>UnsafeBufferPointer&lt;Element&gt;)</div><div>+++ func initialize(from:<wbr>UnsafeMutableBufferPointer&lt;<wbr>Element&gt;)</div><div><br></div><div>I don&#39;t that introduces any behavior that is inconsistent with other methods. `copyBytes` is a totally different thing that only works on trivial types. The currently dominant use case for UnsafeBufferPointer, partially initialized backing store, does not need to use your new convenience methods. It can continue dropping down to pointer+count style initialization/<wbr>deinitialization.</div></div><div><br></div><div>-Andy</div></div></blockquote><div> </div></div></div><div class="gmail_extra">the latest draft does not have <span style="font-family:monospace,monospace">assign(from:</span><wbr><span style="font-family:monospace,monospace">UnsafeMutableBufferPointer&lt;</span><wbr><span style="font-family:monospace,monospace">Element&gt;)</span> or  <span style="font-family:monospace,monospace">initialize(from:</span><wbr><span style="font-family:monospace,monospace">UnsafeMutableBufferPointer&lt;</span><wbr><span style="font-family:monospace,monospace">Element&gt;)</span>, it uses the generic Sequence methods that are already there that do not require that precondition.<br></div></div>