草庐IT

unsafe-pointers

全部标签

unity异常:InvalidOperationException: Burst failed to compile the function pointer `Int32

异常信息具体如下:InvalidOperationException:Burstfailedtocompilethefunctionpointer`Int32ValidateCollinear$BurstManaged(Unity.Mathematics.float2*,Int32,Single)`Unity.Burst.BurstCompiler.Compile(System.ObjectdelegateObj,System.Reflection.MethodInfomethodInfo,System.BooleanisFunctionPointer,System.BooleanisILPo

arrays - 如何在函数中将 swift 数组作为 UnsafePointer<T> 参数传递

我读到,为了将swift变量/常量传递给期望UnsafePointer的参数,可以通过使用变量/常量前缀的“inout”(&符号)符号来完成。所以在下面的代码中,我想将“颜色”数组作为“UnsafePointer”传递给函数CGGradientCreateWithColorComponents(),但是我得到了一个编译器错误:“&与UnsafePointer类型的非输入输出参数一起使用”视觉效果见下图。所以,问题是,如何将swift数组“colors”转换为UnsafePointer?谢谢 最佳答案 将颜色类型显式更改为[CGFlo

swift - 如何通过引用将 UnsafePointer<UInt8> 传递给 C API?

我写了一些Swift2.2代码来与OpenSSL交互CAPI,现在我正在尝试将其转换为Swift3。在swift2中letoctets=pkcs7_d_data(pkcs7_d_sign(receiptPKCS7).memory.contents)varptr=UnsafePointer(octets.memory.data)//nowpasspointerbyreferenceASN1_get_object(&ptr,&length,&type,&xclass,end-ptr)在Swift3中,我不得不做一些改变//useguardsoidonthavetoconstantlyunw

ios - 使用 UnsafeMutablePointer 数组

我正在尝试使用BradLarson出色的GPUImage框架,但我正在努力处理GPUImageHarrisCornerDetectionFilter返回的cornerArray。角点作为UnsafeMutablePointer中的GLFloat数组返回-我想将其转换为CGPoint数组/p>我试过为内存分配空间varcornerPointer=UnsafeMutablePointer.alloc(Int(cornersDetected)*2)但数据似乎没有任何意义——要么是0,要么是1E-32我找到了看起来很完美的答案howtoloopthroughelementsofarrayofi

swift - 'init 不可用 : use 'withMemoryRebound(to:capacity:_)' to temporarily view memory as another layout-compatible type

由于我将我的代码转换为Swift3,所以发生了错误。'initisunavailable:use'withMemoryRebound(to:capacity:_)'totemporarilyviewmemoryasanotherlayout-compatibletype.这是我的代码:funcparseHRMData(data:NSData!){varflags:UInt8varcount:Int=1varzw=[UInt8](count:2,repeatedValue:0)flags=bytes[0]/*----------------FLAGS----------------*//

c - 在 swift 5 中将 void* 参数传递给 c 函数时,'withUnsafeBytes' 被弃用警告

我有一个使用外部提供的c库快速解析FIT文件的库。解析函数将void*data作为参数.为了调用该函数,我使用data.withUnsafeBytes({(ptr:UnsafePointer)in...}转换数据构建c函数的参数并且它工作正常。将Xcode升级到swift5后,我现在收到弃用警告“withUnsafeBytes”已弃用:使用withUnsafeBytes(_:(UnsafeRawBufferPointer)throws->R)rethrows->R相反我不知道如何修复代码以移除已弃用的警告。代码在swift4中运行良好且没有警告我试图将闭包中的参数更改为UnsafeRa

swift - 在 Swift 中转换为不同的 C 结构不安全指针

我想从Swift调用Posix套接字函数socket和bind。socket非常简单——它需要Int32,但是bind导致了一个问题,因为我有一个sockaddr_in指针,但它需要一个sockaddr指针。在C中,这将是一个强制转换,例如:bind(sock,(structsockaddr*)&sockAddress,sizeof(sockAddress))这是Swift中的一个尝试:letsock=socket(PF_INET,SOCK_STREAM,IPPROTO_TCP)varsockAddress=sockaddr_in()bind(sock,&sockAddress,UIn

swift - 如何理解 Swift 中的引用类型或 "Pointer"?

PointersIfyouhaveexperiencewithC,C++,orObjective-C,youmayknowthattheselanguagesusepointerstorefertoaddressesinmemory.ASwiftconstantorvariablethatreferstoaninstanceofsomereferencetypeissimilartoapointerinC,butisnotadirectpointertoanaddressinmemory,anddoesnotrequireyoutowriteanasterisk(*)toindicat

swift - 将 nil 作为 UnsafePointer<UInt8> 传递

在Swift2.2中,我能够传入nil作为需要UnsafePointer的函数的有效参数.在Swift3中,我不能再这样做了:funcmyFuncThatTakesAPointer(buffer:UnsafePointer,length:Int){/****/}myFuncThatTakesAPointer(buffer:nil,length:0)Playgroundexecutionfailed:error:Xcode8Playground-iOS.playground:62:33:error:nilisnotcompatiblewithexpectedargumenttype'Un

pointers - 在 swift 中将 CFContextRef 转换为可变的 void 指针?

我正在尝试将此objc代码转换为swift:CGContextRefcontextRef=CGBitmapContextCreate(NULL,proposedRect.size.width,proposedRect.size.height,CGImageGetBitsPerComponent(imageRef),0,colorSpaceRef,(CGBitmapInfo)kCGImageAlphaPremultipliedFirst);NSGraphicsContext*context=[NSGraphicsContextgraphicsContextWithGraphicsPort