Swift's implicit bridging

I was wondering what's the difference between this code:

import Accelerate

var a: Double = 3
var c: Double = 0

withUnsafePointer(to: &a) { bufferA in
    withUnsafeMutablePointer(to: &c) { bufferC in
        vDSP_minvD(bufferA, vDSP_Stride(1), bufferC, vDSP_Length(1))
    }
}

and this other one:

import Accelerate

var a: Double = 3
var c: Double = 0

vDSP_minvD(&a, vDSP_Stride(1), &c, vDSP_Length(1))

Is the former safer and more efficient, since the latter uses Swift's implicit bridging to pass a double pointer?

Thank you.

Those are essentially equivalent, and neither is safe (nor convenient). Use:

let a = [1.0, 2.0, 3.0]
let c = vDSP.minimum(a)
2 Likes