<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 <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> 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 <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> </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=""><<a href="mailto:gribozavr@gmail.com" target="_blank" class="">gribozavr@gmail.com</a>></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 <<a href="mailto:gribozavr@gmail.com" class="">gribozavr@gmail.com</a>> wrote:<br class="">
> On Thu, Feb 11, 2016 at 12:13 AM, Sergey Kuratov <<a href="mailto:ksubox.swift@gmail.com" class="">ksubox.swift@gmail.com</a>> wrote:<br class="">
>>>> Can I define similar for my Swift classes ?<br class="">
>><br class="">
>>>No. What would be your use case?<br class="">
>><br class="">
>> I also could have my Swift object with several members, but when send to<br class="">
>> native part would like to send address exactly one of members.<br class="">
>> Something like this:<br class="">
>><br class="">
>> // Swift part<br class="">
>><br class="">
>> class ABlock {<br class="">
>><br class="">
>> var channels = 2<br class="">
>><br class="">
>> var samplerate = 44100<br class="">
>><br class="">
>> var buffer : UnsafeMutablePointer<Int16><br class="">
>><br class="">
>> init() {<br class="">
>><br class="">
>> buffer = UnsafeMutablePointer<Int16>.alloc(2048)<br class="">
>><br class="">
>> }<br class="">
>><br class="">
>> deinit {<br class="">
>><br class="">
>> buffer.dealloc(2048)<br class="">
>><br class="">
>> }<br class="">
>><br class="">
>> }<br class="">
>><br class="">
>><br class="">
>> var block = ABlock<br class="">
>> generate(block) <- here I would like to send address of ABlock.buffer to<br class="">
>> native part<br class="">
>><br class="">
>> // C part<br class="">
>> void generate(int16_t *buf) {<br class="">
>> ...<br class="">
>> }<br class="">
><br class="">
> I'd recommend to write a Swift wrapper for your C code that accepts<br class="">
> the class instance, and calls the generate() function with appropriate<br class="">
> 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. Unless you have other requirements though, I'd recommend just<br class="">
storing an array though. 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<i;j++){if(!(i%j)){j=0;break;}}if<br class="">
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <<a href="mailto:gribozavr@gmail.com" class="">gribozavr@gmail.com</a>>*/<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>