如何从[CUnsignedChar]或Array转换为UnsafeMutablePointer?
我有CUnsignedChar形式的数据数组,但需要调用一个期望UnsafeMutablePointer的函数。
详细说明:
我试图在具有此签名的Swift的第三方框架中调用C函数:
int processData(unsigned char * data,int width,int height,int alpha, int beta,void * handler,int * count,void ** results);
我的Swift代码:
var width: Int32 = 0
var height: Int32 = 0
var length: Int32 = 1000
let count = UnsafeMutablePointer<Int32>.allocate(capacity: 1)
let results: UnsafeMutablePointer<UnsafeMutableRawPointer?> = UnsafeMutablePointer.allocate(capacity: 1)
var data = [CUnsignedChar](repeating: 0, count: Int(length))
processData(&data, width, height, 25, 1000, self.handler, count, results)
当它遇到processData调用时我得到了EXC_BAD_ACCESS,但不确定调用中的哪个东西触发了这个。没有任何变量似乎有Swift抱怨的内存地址。