<div dir="ltr">I try to find _fixLifetime in standard library and finally can't :( But function exists in reality and I can call it.<div>I also found some discussion about <a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151228/005017.html">https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151228/005017.html</a> </div><div>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><div class="gmail_quote">On Thu, Feb 11, 2016 at 5:38 PM, 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"><div class="HOEnZb"><div class="h5">On Thu, Feb 11, 2016 at 12:19 AM, Dmitri Gribenko <<a href="mailto:gribozavr@gmail.com">gribozavr@gmail.com</a>> wrote:<br>
> On Thu, Feb 11, 2016 at 12:13 AM, Sergey Kuratov <<a href="mailto:ksubox.swift@gmail.com">ksubox.swift@gmail.com</a>> wrote:<br>
>>>> Can I define similar for my Swift classes ?<br>
>><br>
>>>No. What would be your use case?<br>
>><br>
>> I also could have my Swift object with several members, but when send to<br>
>> native part would like to send address exactly one of members.<br>
>> Something like this:<br>
>><br>
>> // Swift part<br>
>><br>
>> class ABlock {<br>
>><br>
>> var channels = 2<br>
>><br>
>> var samplerate = 44100<br>
>><br>
>> var buffer : UnsafeMutablePointer<Int16><br>
>><br>
>> init() {<br>
>><br>
>> buffer = UnsafeMutablePointer<Int16>.alloc(2048)<br>
>><br>
>> }<br>
>><br>
>> deinit {<br>
>><br>
>> buffer.dealloc(2048)<br>
>><br>
>> }<br>
>><br>
>> }<br>
>><br>
>><br>
>> var block = ABlock<br>
>> generate(block) <- here I would like to send address of ABlock.buffer to<br>
>> native part<br>
>><br>
>> // C part<br>
>> void generate(int16_t *buf) {<br>
>> ...<br>
>> }<br>
><br>
> I'd recommend to write a Swift wrapper for your C code that accepts<br>
> the class instance, and calls the generate() function with appropriate<br>
> arguments.<br>
<br>
</div></div>Oh, and since your class stores an unsafe pointer (and not an array),<br>
you'd need to call _fixLifetime() on it after the your C function<br>
returns, to ensure that the class instance can't be deallocated before<br>
then. Unless you have other requirements though, I'd recommend just<br>
storing an array though. Then you wouldn't need to care about<br>
_fixLifetime().<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>