How to map an UnsafePointer to another type?

Viewed 107

I'm trying to convert an UnsafePointer<UInt16> to an UnsafePointer<Float> and so far I ended with this solution:

let bufferSize = 1024
let buffer: UnsafePointer<UInt16> = ....
let tmp = UnsafeBufferPointer(start: buffer, count: bufferSize).map(Float.init)
let converted: UnsafePointer<Float> = UnsafePointer(tmp)

It works but I have the feeling it's not an efficient way since I'm creating an intermediate Array... Is there a better way to do that ?

1 Answers
Related