Inter-operability of Swift arrays with C?

前端 未结 4 1932
终归单人心
终归单人心 2021-02-02 09:46

How can one pass or copy the data in a C array, such as

float foo[1024];

, between C and Swift functions that use fixed size arrays, such as d

4条回答
  •  逝去的感伤
    2021-02-02 10:40

    As of Beta 5, one can just use pass &array The following example passes 2 float arrays to a vDSP C function:

    let logLen = 10
    let len = Int(pow(2.0, Double(logLen)))
    let setup : COpaquePointer = vDSP_create_fftsetup(vDSP_Length(logLen), FFTRadix(kFFTRadix2))
    
    var myRealArray = [Float](count: len, repeatedValue: 0.0)
    var myImagArray = [Float](count: len, repeatedValue: 0.0)
    var cplxData = DSPSplitComplex(realp: &myRealArray, imagp: &myImagArray)
    
    vDSP_fft_zip(setup, &cplxData, 1, vDSP_Length(logLen),FFTDirection(kFFTDirection_Forward))
    

提交回复
热议问题