<div dir="ltr">Thank you! This, in conjunction with a later call to bindMemory(to: capacity:), was exactly what I needed.</div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Sep 16, 2016 at 9:47 AM, Quinn &quot;The Eskimo!&quot; via swift-users <span dir="ltr">&lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
On 15 Sep 2016, at 22:11, Lane Schwartz via swift-users &lt;<a href="mailto:swift-users@swift.org">swift-users@swift.org</a>&gt; wrote:<br>
<br>
&gt; Can anyone help me get the equivalent functionality in Swift 3?<br>
<br>
</span>I think the main issue here is that, in Swift 3, unsafe pointers, in their various flavours, don’t explicitly support nil.  Rather, nil is modelled like it is for any other type, via `Optional`.  You can read all about this change in SE-0055 [1]<br>
<br>
So, if you have an C API like this:<br>
<br>
extern int HackAlloc(void ** bufPtrPtr, size_t bufSize);<br>
extern void HackFree(void * bufPtr);<br>
<br>
you can call it like this:<br>
<br>
var buf: UnsafeMutableRawPointer? = nil<br>
let result = HackAlloc(&amp;buf, 1024)<br>
if result == 0 {<br>
    HackFree(buf)<br>
}<br>
<br>
This is very similar to what you currently have except that `buf` is explicitly made optional.<br>
<br>
The other difference is that `buf` is a ‘raw’ pointer, which means you have to understand Swift 3’s type aliasing rules.  You can read about the details in SE-0107 [2] bug a good place to start is the “UnsafeRawPointer Migration” section of the Swift 3 migration guide.<br>
<br>
&lt;<a href="https://swift.org/migration-guide/se-0107-migrate.html" rel="noreferrer" target="_blank">https://swift.org/migration-<wbr>guide/se-0107-migrate.html</a>&gt;<br>
<br>
Share and Enjoy<br>
--<br>
Quinn &quot;The Eskimo!&quot;                    &lt;<a href="http://www.apple.com/developer/" rel="noreferrer" target="_blank">http://www.apple.com/<wbr>developer/</a>&gt;<br>
Apple Developer Relations, Developer Technical Support, Core OS/Hardware<br>
<br>
[1]: &lt;<a href="https://github.com/apple/swift-evolution/blob/master/proposals/0055-optional-unsafe-pointers.md" rel="noreferrer" target="_blank">https://github.com/apple/<wbr>swift-evolution/blob/master/<wbr>proposals/0055-optional-<wbr>unsafe-pointers.md</a>&gt;<br>
<br>
[2]: &lt;<a href="https://github.com/apple/swift-evolution/blob/master/proposals/0107-unsaferawpointer.md" rel="noreferrer" target="_blank">https://github.com/apple/<wbr>swift-evolution/blob/master/<wbr>proposals/0107-<wbr>unsaferawpointer.md</a>&gt;<br>
<br>
______________________________<wbr>_________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-users</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">When a place gets crowded enough to require ID&#39;s, social collapse is not<br>far away.  It is time to go elsewhere.  The best thing about space travel<br>is that it made it possible to go elsewhere.<br>                -- R.A. Heinlein, &quot;Time Enough For Love&quot;</div>
</div>