[swift-users] How to get UnsafePointer or UnsafeMutablePointer from ContiguousArray?

Sergey Kuratov ksubox.swift at gmail.com
Thu Feb 11 02:20:57 CST 2016


Got it.

Thank you.

On Thu, Feb 11, 2016 at 5:19 PM, Dmitri Gribenko <gribozavr at gmail.com>
wrote:

> On Thu, Feb 11, 2016 at 12:13 AM, Sergey Kuratov <ksubox.swift at gmail.com>
> wrote:
> >>> Can I define similar for my Swift classes ?
> >
> >>No.  What would be your use case?
> >
> > I also could have my Swift object with several members, but when send to
> > native part would like to send address exactly one of members.
> > Something like this:
> >
> > // Swift part
> >
> > class ABlock {
> >
> > var channels = 2
> >
> > var samplerate = 44100
> >
> > var  buffer : UnsafeMutablePointer<Int16>
> >
> > init() {
> >
> > buffer = UnsafeMutablePointer<Int16>.alloc(2048)
> >
> > }
> >
> > deinit {
> >
> > buffer.dealloc(2048)
> >
> > }
> >
> > }
> >
> >
> > var block = ABlock
> > generate(block) <- here I would like to send address of ABlock.buffer to
> > native part
> >
> > // C part
> > void generate(int16_t *buf) {
> > ...
> > }
>
> I'd recommend to write a Swift wrapper for your C code that accepts
> the class instance, and calls the generate() function with appropriate
> arguments.
>
> Dmitri
>
> --
> main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
> (j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160211/2ed307a6/attachment.html>


More information about the swift-users mailing list