简体   繁体   English

NSCore,NSOperation或GCD是否用于CoreMotion和准确的计时目的?

[英]NSThread, NSOperation or GCD for CoreMotion and accurate timing purposes?

I'm looking to do some high precision core motion reading (>=100Hz if possible) and motion analysis on the iPhone 4+ which will run continuously for the duration of the main part of the app. 我希望在iPhone 4+上进行一些高精度的核心运动读取(如果可能,>> = 100Hz)和运动分析,这些运动将在应用程序的主要部分持续运行。 It's imperative that the motion response and the signals that the analysis code sends out are as free from lag as possible. 至关重要的是,运动响应和分析代码发出的信号应尽可能避免滞后。

My original plan was to launch a dedicated NSThread based on the code in the metronome project as referenced here: Accurate timing in iOS , along with a protocol for motion analysers to link in and use the thread. 我最初的计划是根据节拍器项目中的代码启动一个专用的NSThread,如下所示: iOS中的准确计时 ,以及用于运动分析器链接和使用线程的协议。 I'm wondering whether GCD or NSOperation queues might be better? 我想知道GCD或NSOperation队列是否会更好?

My impression after copious reading is that they are designed to handle a quantity of discrete, one-off operations rather than a small number of operations performed over and over again on a regular interval and that using them every millisecond or so might inadvertently create a lot of thread creation/destruction overhead. 在大量阅读之后,我的印象是,它们被设计为处理大量离散的一次性操作,而不是定期执行一次又一次的少量操作,每毫秒左右使用它们可能会无意中产生很多创建/销毁线程的开销。 Does anyone have any experience here? 有人在这里有经验吗?

I'm also wondering about the performance implications of an endless while loop in a thread (such as in the code in the above link). 我还想知道线程中无休止的while循环对性能的影响(例如上述链接中的代码)。 Does anyone know more about how things work under the hood with threads? 有人知道线程在幕后如何工作吗? I know that iPhone4 (and under) are single core processors and use some sort of intelligent multitasking (pre-emptive?) which switches threads based on various timing and I/O demands to create the effect of parallelism... 我知道iPhone4(及更低版本)是单核处理器,并使用某种智能多任务处理(抢先式吗?),它会根据各种时序和I / O需求切换线程,以产生并行效果。

If you have a thread that has a simple "while" loop running endlessly but only doing any additional work every millisecond or so, does the processor's switching algorithm consider the endless loop a "high demand" on resources thus hogging them from other threads or will it be smart enough to allocate resources more heavily towards other threads in the "downtime" between additional code execution? 如果您的线程有一个简单的“ while”循环无休止地运行,但每毫秒才执行任何其他工作,那么处理器的切换算法是否认为该无休止的循环是对资源的“高需求”,因此将其从其他线程中拖累了或是否足够聪明,可以在额外的代码执行之间的“停机时间”内向其他线程分配更多资源?

Thanks in advance for the help and expertise... 预先感谢您的帮助和专业知识...

IMO the bottleneck are rather the sensors. IMO的瓶颈在于传感器。 The actual update frequency is most often not equal to what you have specified. 实际更新频率通常不等于您指定的频率。 See update frequency set for deviceMotionUpdateInterval it's the actual frequency? 请参阅为deviceMotionUpdateInterval设置的更新频率,它是实际频率? and Actual frequency of device motion updates lower than expected, but scales up with setting 设备运动的实际频率更新低于预期,但随着设置的增加而增加

Some time ago I made a couple of measurements using Core Motion and the raw sensor data as well. 不久前,我还使用Core Motion和原始传感器数据进行了一些测量。 I needed a high update rate too because I was doing a Simpson integration and thus wnated to minimise errors. 我也需要很高的更新率,因为我正在进行Simpson集成,因此可以最大程度地减少错误。 It turned out that the real frequency is always lower and that there is limit at about 80 Hz. 事实证明,实际频率始终较低,并且极限约为80 Hz。 It was an iPhone 4 running iOS 4. But as long as you don't need this for scientific purposes in most cases 60-70 Hz should fit your needs anyway. 那是一台运行iOS 4的iPhone4。但是,只要出于科学目的您不需要它,在大多数情况下60-70 Hz仍然可以满足您的需求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM