下面的代码只是尝试使用 将值从一个指针复制到另一个指针,但大约有三分之一的时间cblas_ccopy
会导致错误。malloc: *** error ... incorrect checksum for freed object
为什么它总是不工作?
import Accelerate
func testCopy() {
// set capacity
let capacity: Int = 1000
// destination array
let destinationArray = UnsafeMutablePointer<Float>.allocate(capacity: capacity)
destinationArray.initialize(repeating: 0, count: capacity)
// source array
let sourceArray = UnsafeMutablePointer<Float>.allocate(capacity: capacity)
sourceArray.initialize(repeating: 1, count: capacity)
// copy values
cblas_ccopy(Int32(capacity),
UnsafeRawPointer(sourceArray),
1,
UnsafeMutableRawPointer(destinationArray),
1)
// check to see if values were copied
for idx in 0..<capacity {
print(idx, destinationArray[idx])
}
}
testCopy()
将其作为单元测试运行时,错误为objc[44736]: autorelease pool page 0x7fecb903c000 corrupted
. 将其作为脚本运行时,错误为incorrect checksum
.
我尝试在其中设置断点,malloc_error_break
但我不明白如何解释输出。
我还尝试将sourceArray
和作为参数传递destinationArray
,cblas_ccopy
而不将它们转换为原始指针,但这并没有帮助。