Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
added 949 characters in body
Source Link
Martin R
  • 541.4k
  • 98
  • 1.3k
  • 1.4k

You have to "rebind" the pointer:

values.withUnsafeMutableBufferPointer { $0.baseAddress!.withMemoryRebound(to: DSPDoubleComplex.self, capacity: values.count/2) { valuesAsComplex in // ... } } 

Inside the closure valuesAsComplex is a UnsafeMutablePointer<DSPDoubleComplex> and can be passed to DSP functions.

You must not pass the pointer to the element storage to the outside of the closure as the documentation clearly states:

The pointer argument is valid only for the duration of the closure’s execution.

That may work by chance, but there is no guarantee that after the execution of the closure, the elements storage is still at the same memory address (or that the array even exists, since the pointer is not a strong reference which ensures the lifetime of the storage).


In your case that would be

 tempSplitComplex = DSPDoubleSplitComplex(realp: &mag, imagp: &phase) vDSP_ztocD(&tempSplitComplex, 1, &tempComplex, 2, N2); tempComplex.withUnsafeMutableBufferPointer { $0.baseAddress!.withMemoryRebound(to: Double.self, capacity: values.count * 2) { complexAsDouble in vDSP_rectD(complexAsDouble, 2, complexAsDouble, 2, N2); } } vDSP_ctozD(&tempComplex, 2, &tempSplitComplex, 1, N2); 

and

 var result = [Double](repeating: 0.0, count: N/2) result.withUnsafeMutableBufferPointer { $0.baseAddress!.withMemoryRebound(to: DSPDoubleComplex.self, capacity: result.count/2) { resultAsComplex in vDSP_ztocD(&tempSplitComplex, 1, resultAsComplex, 2, N2); } } 

You have to "rebind" the pointer:

values.withUnsafeMutableBufferPointer { $0.baseAddress!.withMemoryRebound(to: DSPDoubleComplex.self, capacity: values.count/2) { valuesAsComplex in // ... } } 

Inside the closure valuesAsComplex is a UnsafeMutablePointer<DSPDoubleComplex> and can be passed to DSP functions.

You must not pass the pointer to the element storage to the outside of the closure as the documentation clearly states:

The pointer argument is valid only for the duration of the closure’s execution.

That may work by chance, but there is no guarantee that after the execution of the closure, the elements storage is still at the same memory address (or that the array even exists, since the pointer is not a strong reference which ensures the lifetime of the storage).

You have to "rebind" the pointer:

values.withUnsafeMutableBufferPointer { $0.baseAddress!.withMemoryRebound(to: DSPDoubleComplex.self, capacity: values.count/2) { valuesAsComplex in // ... } } 

Inside the closure valuesAsComplex is a UnsafeMutablePointer<DSPDoubleComplex> and can be passed to DSP functions.

You must not pass the pointer to the element storage to the outside of the closure as the documentation clearly states:

The pointer argument is valid only for the duration of the closure’s execution.

That may work by chance, but there is no guarantee that after the execution of the closure, the elements storage is still at the same memory address (or that the array even exists, since the pointer is not a strong reference which ensures the lifetime of the storage).


In your case that would be

 tempSplitComplex = DSPDoubleSplitComplex(realp: &mag, imagp: &phase) vDSP_ztocD(&tempSplitComplex, 1, &tempComplex, 2, N2); tempComplex.withUnsafeMutableBufferPointer { $0.baseAddress!.withMemoryRebound(to: Double.self, capacity: values.count * 2) { complexAsDouble in vDSP_rectD(complexAsDouble, 2, complexAsDouble, 2, N2); } } vDSP_ctozD(&tempComplex, 2, &tempSplitComplex, 1, N2); 

and

 var result = [Double](repeating: 0.0, count: N/2) result.withUnsafeMutableBufferPointer { $0.baseAddress!.withMemoryRebound(to: DSPDoubleComplex.self, capacity: result.count/2) { resultAsComplex in vDSP_ztocD(&tempSplitComplex, 1, resultAsComplex, 2, N2); } } 
added 308 characters in body
Source Link
Martin R
  • 541.4k
  • 98
  • 1.3k
  • 1.4k

You have to "rebind" the pointer:

values.withUnsafeMutableBufferPointer { $0.baseAddress!.withMemoryRebound(to: DSPDoubleComplex.self, capacity: values.count/2) { valuesAsComplex in // ... } } 

Inside the closure valuesAsComplex is a UnsafeMutablePointer<DSPDoubleComplex> and can be passed to DSP functions.

You must not pass the pointer to the element storage to the outside of the closure as the documentation clearly states:

The pointer argument is valid only for the duration of the closure’s execution.

That may work by chance, but there is no guarantee that after the execution of the closure, the elements storage is still at the same memory address (or that the array even exists, since the pointer is not a strong reference which ensures the lifetime of the storage).

You have to "rebind" the pointer:

values.withUnsafeMutableBufferPointer { $0.baseAddress!.withMemoryRebound(to: DSPDoubleComplex.self, capacity: values.count/2) { valuesAsComplex in // ... } } 

Inside the closure valuesAsComplex is a UnsafeMutablePointer<DSPDoubleComplex> and can be passed to DSP functions.

You must not pass the pointer to the element storage to the outside of the closure as the documentation clearly states:

The pointer argument is valid only for the duration of the closure’s execution.

You have to "rebind" the pointer:

values.withUnsafeMutableBufferPointer { $0.baseAddress!.withMemoryRebound(to: DSPDoubleComplex.self, capacity: values.count/2) { valuesAsComplex in // ... } } 

Inside the closure valuesAsComplex is a UnsafeMutablePointer<DSPDoubleComplex> and can be passed to DSP functions.

You must not pass the pointer to the element storage to the outside of the closure as the documentation clearly states:

The pointer argument is valid only for the duration of the closure’s execution.

That may work by chance, but there is no guarantee that after the execution of the closure, the elements storage is still at the same memory address (or that the array even exists, since the pointer is not a strong reference which ensures the lifetime of the storage).

added 308 characters in body
Source Link
Martin R
  • 541.4k
  • 98
  • 1.3k
  • 1.4k

You have to "rebind" the pointer:

values.withUnsafeMutableBufferPointer { $0.baseAddress!.withMemoryRebound(to: DSPDoubleComplex.self, capacity: values.count/2) { valuesAsComplex in // ... } } 

Inside the closure valuesAsComplex is a UnsafeMutablePointer<DSPDoubleComplex> and can be passed to DSP functions.

You must not pass the pointer to the element storage to the outside of the closure as the documentation clearly states:

The pointer argument is valid only for the duration of the closure’s execution.

You have to "rebind" the pointer:

values.withUnsafeMutableBufferPointer { $0.baseAddress!.withMemoryRebound(to: DSPDoubleComplex.self, capacity: values.count/2) { valuesAsComplex in // ... } } 

Inside the closure valuesAsComplex is a UnsafeMutablePointer<DSPDoubleComplex> and can be passed to DSP functions.

You have to "rebind" the pointer:

values.withUnsafeMutableBufferPointer { $0.baseAddress!.withMemoryRebound(to: DSPDoubleComplex.self, capacity: values.count/2) { valuesAsComplex in // ... } } 

Inside the closure valuesAsComplex is a UnsafeMutablePointer<DSPDoubleComplex> and can be passed to DSP functions.

You must not pass the pointer to the element storage to the outside of the closure as the documentation clearly states:

The pointer argument is valid only for the duration of the closure’s execution.

Source Link
Martin R
  • 541.4k
  • 98
  • 1.3k
  • 1.4k
Loading