<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)">Do you know of any resources to brush up on the pointer aspect of swift ? </div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr">
<p><b><font color="#cc0000">___________________________________</font></b></p><p><b>James⎥Head of Trolls</b></p><p><b><font color="#cc0000"><a href="mailto:james@supmenow.com" target="_blank">james@supmenow.com</a>⎥<a href="http://supmenow.com" target="_blank">supmenow.com</a></font></b></p><p><b><font size="2">Sup</font></b></p><p><b><font size="2">Runway East
</font></b></p><p><b><font size="2">10 Finsbury Square</font></b></p><p><b><font size="2">London</font></b></p><p><b><font size="2">
EC2A 1AF </font></b></p></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div>
<br><div class="gmail_quote">On 29 July 2016 at 09:10, 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 Fri, Jul 29, 2016 at 12:55 AM, James Campbell <<a href="mailto:james@supmenow.com">james@supmenow.com</a>> wrote:<br>
> So this:<br>
><br>
> if let data = someArrayGeneratingFunction() {<br>
> cFunction(UnsafeMutablePointer(data))<br>
> }<br>
><br>
> Has issues with the array passed to c getting corrupted, but this doesn't:<br>
><br>
> let data = someArrayGeneratingFunction()<br>
><br>
> if let data = data {<br>
> cFunction(UnsafeMutablePointer(data))<br>
> }<br>
<br>
</span>Neither piece of code is guaranteed to work. (You are just getting<br>
lucky that the second one happens to work.) Array-to-pointer<br>
conversion only extends the lifetime of the array until the immediate<br>
function call returns. So after UnsafeMutablePointer(data) returns,<br>
the array can be freed.<br>
<br>
Use someArrayGeneratingFunction.withUnsafeMutableBuffer { ... } instead.<br>
<div class="HOEnZb"><div class="h5"><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>
</div></div></blockquote></div><br></div>