<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Aug 8, 2017 at 9:38 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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><span class=""><div><br></div><blockquote type="cite"><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"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div><div><div>&gt; UnsafeMutableRawBufferPointer.<wbr>allocate(bytes:alignedTo:)</div><div><br></div><div>Well, I think it&#39;s somewhat ridiculous for users to write this every time they allocate a buffer:</div><div><br></div><div>`UnsafeMutableRawBufferPointer<wbr>.allocate(bytes: size, alignedTo: MemoryLayout&lt;UInt&gt;.alignment)`</div><div><br></div><div>If anyone reading the code is unsure about the Swift API&#39;s alignment</div><div>guarantee, it&#39;s trivial to check the API docs.</div><div><br></div><div>You could introduce a clearly documented default `alignedTo`</div><div>argument. The reason I didn&#39;t do that is that the runtime won&#39;t</div><div>respect it anyway. But I think it would be fair to go ahead with the</div><div>API and file a bug against the runtime.</div></div></div></blockquote><div><br></div><div>Default argument of<span class="m_7821494737473580892Apple-converted-space"> </span><span style="font-family:monospace,monospace">MemoryLayout&lt;Int&gt;.alignment</span><span class="m_7821494737473580892Apple-converted-space"><wbr> </span>is the way to go but as you said i don’t know if that is actually allowed/works. An alternative is to have two allocate methods each, one that takes an alignment argument and one that doesn’t (and aligns to pointer alignment) but that feels inelegant. Default arguments would be better.<br></div></div></blockquote><div><br></div></span><div>Default argument makes sense to me too. Then the raw buffer pointer and regular raw pointer APIs can be consistent with each other.</div><div><br></div><div>Runtime bug: <a href="https://bugs.swift.org/browse/SR-5664" target="_blank">https://bugs.swift.org/browse/<wbr>SR-5664</a></div><span class=""></span><br></div></div></blockquote><div><br></div><div>yikes i was not aware of this. I don’t think it’s bad enough to warrant dropping the argument like with <span style="font-family:monospace,monospace">deallocate(capacity:)</span> but I can imagine bad things happening to code that crams extra inhabitants into pointers.<br></div></div><br></div></div>