草庐IT

DISPATCH_QUEUE_T

全部标签

swift - 使用 dispatch_after swift 延迟 'glitch'

目前我有一个延时函数如下://Delayfunctionfromhttp://stackoverflow.com/questions/24034544/dispatch-after-gcd-in-swift/24318861#24318861funcdelay(delay:Double,closure:()->()){dispatch_after(dispatch_time(DISPATCH_TIME_NOW,Int64(delay*Double(NSEC_PER_SEC))),dispatch_get_main_queue(),closure)}此代码可满足我的需要,但一旦延迟超过1

Swift dispatch_async 导致 EXC_BAD_ACCESS 错误

在我的Swift项目中,我试图在后台线程中处理一个FIFO队列(我在这里将其称为列表以避免混淆)。当我使用dispatch_async时,它会在仅执行列表的某些部分后导致EXC_BAD_ACCESS错误。我已尽可能将代码简化为以下Playground代码。在playground中,当main_thread设置为true时,代码会处理列表中的所有100个项目。如果为假,则只会处理少数项目。如果代码在项目中,当main_thread为false时会出现EXC_BAD_ACCESS。显然,我也尝试过指定一个串行队列,但这似乎没有帮助。我缺少或不理解什么?谢谢。importUIKitletma

swift - 完成处理程序 dispatch_async 出错?

这个问题在这里已经有了答案:HowdoIdispatch_sync,dispatch_async,dispatch_after,etcinSwift3,Swift4,andbeyond?(6个答案)关闭5年前。我在下面的函数中有完成处理程序staticfuncfetchFeatureApp(completionHandler:@escaping([AppCategory1])->()){leturlString="http://ebmacs.net/ubereats/Api/all_product?id=1"leturl=URL(string:urlString)!URLSession

arrays - 数组在 dispatch_barrier_sync 上损坏

我有2个将数据附加到数组的函数和一个处理它的函数。我使用dispatch_barrier_sync来防止其他函数在我处理数据时更改数据。内部追加函数:autoreleasepool{dispatch_barrier_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0)){[weakself]()->Voidinself?.bufferVector_.append(data)}}内部流程函数:autoreleasepool{dispatch_barrier_sync(dispatch_get_global_qu

swift - 将 Swift 类标记为 final 是否也会使所有包含的 var、let 和函数自动获得 Static Dispatch 的好处?

我正试图从我的应用程序中榨取最后一点性能。我尝试尽可能在类上使用Structs(没有状态共享,默认情况下直接分派(dispatch)等等)。但是我的ViewController和UIView对象显然仍然是类。出于性能原因,我想对我的每一个方法和数据成员强制执行直接调度。我是否还需要在我的类(class)中标记每个var、let和funcfinal,或者是是否足以将托管类标记为最终类,以便其下的所有内容都可以利用直接方法分派(dispatch)?换句话说:在每个方法和变量之前都粘贴final非常乏味。所以我希望将它放在类(class)本身上具有强制直接dispatch所有类(class)

heap & max priority queue

heap&maxpriorityqueuesection1:heap0概述1(二叉)堆是1个数组,可视为完全二叉树root:A[0]`除最底层外`,树`完全填满:每层从左向右fill`2heap数组A2个属性(1)A.length:数组元素数(2)A.heapSize:有效堆元素数3nodeIndexi=0..A.length-1=>parentIndex/lcIndex/rcIndexindexparentIndex(i)returnfloor((i+1)/2-1)=(i+1)/2-1lcIndex(i)return2*(i+1)-1=2*i+1rcIndex(i)return2*(i+1)

C++:stack和queue的使用以及底层实现

stack和queue的使用以及底层实现1.适配器模式2.stack的介绍和使用2.1stack的介绍2.2stack的使用3.queue的介绍和使用3.1queue的介绍3.2queue的使用4.仿函数介绍5.priority_queue的介绍和使用5.1priority_queue的介绍5.2priority_queue的使用6.deque的介绍6.1deque的实现原理6.2deque的缺陷6.3选择deque作为stack和queue的底层默认容器的原因7.模拟实现7.1stack的模拟实现7.2queue的模拟实现7.3priority_queue的模拟实现1.适配器模式适配器是一种

Java 集合之 Queue

1.线性数据结构数组、链表、栈、队列1.1队列Queue是一种遵循先进先出(FIFO:FirstIn,FirstOut)原则的数据集合,数据在Queue中的流动是单向的,从队尾流向队首1.2Queue接口//继承基础集合接口CollectionpublicinterfaceQueueextendsCollection{booleanadd(Ee);//throwinganIllegalStateExceptionifnospacebooleanoffer(Ee);//RetrievesandremovestheheadofthisqueueEremove();Epoll();//Retriev

multithreading - Swift dispatch_after throwing is not a prefix unary operator 错误

我有以下代码:importSpriteKitimportFoundationclassGameScene:SKScene{varoccupiedCoordinates:NSMutableArray=NSMutableArray()funcaddShape(){//...shape.position=CGPoint(x:actualX,y:actualY)self.occupiedCoordinates.addObject(NSValue(CGPoint:shape.position))lethalfDuration=random(min:CGFloat(0.5),max:CGFloat

ios - Swift:我可以加减 `dispatch_time_t` 变量吗?

我需要在iOS中使用Swift做一些时间计算。我必须使用dispatch_walltime。我希望这可以被视为公理化。在涉及时间数学的地方,我想我可能会得到“只需使用NSDate”的响应,但请相信它:我必须遵守dispatch_walltime。现在,很明显为什么有人会建议使用NSDate,因为当您使用NSTimeInterval和NSDate以及那些好东西时,它非常棒轻松制作自定义时间戳并比较它们并进行各种时间数学计算。但我必须使用dispatch_time_t,特别是像这样创建的dispatch_walltime://GetthetimeIntervalofnow.letnowIn