<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">withExtendedLifetime is the function you're looking for.</div><br class=""><div><blockquote type="cite" class=""><div class="">On Feb 11, 2016, at 1:10 , Sergey Kuratov via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">I try to find _fixLifetime in standard library and finally can't :( But function exists in reality and I can call it.<div class="">I also found some discussion about&nbsp;<a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151228/005017.html" class="">https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151228/005017.html</a>&nbsp;</div><div class="">So as I can understand it's not fixed API to manage scoped life and probably will be changed in the future.</div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Thu, Feb 11, 2016 at 5:38 PM, Dmitri Gribenko <span dir="ltr" class="">&lt;<a href="mailto:gribozavr@gmail.com" target="_blank" class="">gribozavr@gmail.com</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Thu, Feb 11, 2016 at 12:19 AM, Dmitri Gribenko &lt;<a href="mailto:gribozavr@gmail.com" class="">gribozavr@gmail.com</a>&gt; wrote:<br class="">
&gt; On Thu, Feb 11, 2016 at 12:13 AM, Sergey Kuratov &lt;<a href="mailto:ksubox.swift@gmail.com" class="">ksubox.swift@gmail.com</a>&gt; wrote:<br class="">
&gt;&gt;&gt;&gt; Can I define similar for my Swift classes ?<br class="">
&gt;&gt;<br class="">
&gt;&gt;&gt;No.&nbsp; What would be your use case?<br class="">
&gt;&gt;<br class="">
&gt;&gt; I also could have my Swift object with several members, but when send to<br class="">
&gt;&gt; native part would like to send address exactly one of members.<br class="">
&gt;&gt; Something like this:<br class="">
&gt;&gt;<br class="">
&gt;&gt; // Swift part<br class="">
&gt;&gt;<br class="">
&gt;&gt; class ABlock {<br class="">
&gt;&gt;<br class="">
&gt;&gt; var channels = 2<br class="">
&gt;&gt;<br class="">
&gt;&gt; var samplerate = 44100<br class="">
&gt;&gt;<br class="">
&gt;&gt; var&nbsp; buffer : UnsafeMutablePointer&lt;Int16&gt;<br class="">
&gt;&gt;<br class="">
&gt;&gt; init() {<br class="">
&gt;&gt;<br class="">
&gt;&gt; buffer = UnsafeMutablePointer&lt;Int16&gt;.alloc(2048)<br class="">
&gt;&gt;<br class="">
&gt;&gt; }<br class="">
&gt;&gt;<br class="">
&gt;&gt; deinit {<br class="">
&gt;&gt;<br class="">
&gt;&gt; buffer.dealloc(2048)<br class="">
&gt;&gt;<br class="">
&gt;&gt; }<br class="">
&gt;&gt;<br class="">
&gt;&gt; }<br class="">
&gt;&gt;<br class="">
&gt;&gt;<br class="">
&gt;&gt; var block = ABlock<br class="">
&gt;&gt; generate(block) &lt;- here I would like to send address of ABlock.buffer to<br class="">
&gt;&gt; native part<br class="">
&gt;&gt;<br class="">
&gt;&gt; // C part<br class="">
&gt;&gt; void generate(int16_t *buf) {<br class="">
&gt;&gt; ...<br class="">
&gt;&gt; }<br class="">
&gt;<br class="">
&gt; I'd recommend to write a Swift wrapper for your C code that accepts<br class="">
&gt; the class instance, and calls the generate() function with appropriate<br class="">
&gt; arguments.<br class="">
<br class="">
</div></div>Oh, and since your class stores an unsafe pointer (and not an array),<br class="">
you'd need to call _fixLifetime() on it after the your C function<br class="">
returns, to ensure that the class instance can't be deallocated before<br class="">
then.&nbsp; Unless you have other requirements though, I'd recommend just<br class="">
storing an array though.&nbsp; Then you wouldn't need to care about<br class="">
_fixLifetime().<br class="">
<div class="HOEnZb"><div class="h5"><br class="">
Dmitri<br class="">
<br class="">
--<br class="">
main(i,j){for(i=2;;i++){for(j=2;j&lt;i;j++){if(!(i%j)){j=0;break;}}if<br class="">
(j){printf("%d\n",i);}}} /*Dmitri Gribenko &lt;<a href="mailto:gribozavr@gmail.com" class="">gribozavr@gmail.com</a>&gt;*/<br class="">
</div></div></blockquote></div><br class=""></div>
_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></div></blockquote></div><br class=""></body></html>