gpt4 book ai didi

swift - 在 Swift 3 中创建一个 UnsafeMutablePointer> 参数

转载 作者:行者123 更新时间:2023-11-28 06:34:29 53 4
gpt4 key购买 nike

Accelerate 框架的 Swift 签名 vDSP_biquadm()函数包括 UnsafeMutablePointer<UnsafePointer<Float>> 的参数类型和 UnsafeMutablePointer<UnsafeMutablePointer<Float>> .

如何在 Swift 3 中声明和创建此类类型,然后使用对多个类型为 [Float] 的 Swift 数组的引用来填充这些指针数组? .

最佳答案

当您需要为 UnsafeMutablePointer<T> 传递多个值时参数,需要声明一个类型为[T]的变量(又名 Array<T> )并将其作为 inout 参数传递。在你的情况下 TUnsafeMutablePointer<Float> .

所以,如果您想从 [Float] 开始,你可能需要这样写:

let input: [Float] = [/*...*/]
var output: [Float] = Array(repeating: 0, count: outputTotalSize)
input.withUnsafeBufferPointer {inBuf in
let inputPtr = inBuf.baseAddress!
output.withUnsafeMutableBufferPointer {outBuf in
let outputPtr = outBuf.baseAddress!
var pInputs: [UnsafePointer<Float>] = [inputPtr,/*...*/]
var pOutputs: [UnsafeMutablePointer<Float>] = [outputPtr/*...*/]
vDSP_biquadm(setup, &pInputs, inStride, &pOutputs, outStride, length)
}
}

关于swift - 在 Swift 3 中创建一个 UnsafeMutablePointer<UnsafeMutablePointer<Float>> 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39441335/

53 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com