实时清除数据容器的内容 [英] Purge the contents of a data container in real time

查看:133
本文介绍了实时清除数据容器的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题最好由下面的架构解释

My problem is best explained by the architecture below

基本上,我必须实时清除 NSMutableData 对象(或任何其他对象)的内容,即我可以不阻止其包含的线程。

Basically, I have to purge the contents of an NSMutableData object (or any other object, for that matter) in real time, i.e., I can't block its containing thread. Is there a way/API to do this?

更新:由于在下面的评论中提到。我实时接收音频数据包到主线程,并立即路由到一个专用的音频池线程..(这是为什么我有这么多的线程是b / ci没有控制进入包的接收。他们来实时+播放速率比接收数据的速率慢得多。因此独立的音频池线程和阅读器线程) / p>

update: As mentioned in the comments below.. i'm receiving audio packets in real time to the main thread and immediately route it to a dedicated audio pool thread.. (the reason why i got so many threads is b/c i have no control over the reception of the incoming packets.. they come in real time + the rate of playback is a lot slower than the rate of receiving data.. thus the seperate audio pool thread and the reader thread)

推荐答案

通函缓冲区aka环形缓冲区与NSMutableData很好地工作,因为你可以直接使用字节数组作为缓冲区。

Circular buffers aka ring buffers work nicely with NSMutableData since you can use the byte array directly as the buffer.

看看设计,我不明白为什么你需要这么多缓冲区。似乎有一个线程和两个缓冲区太多。为什么不是只有一个环形缓冲区,填充(它的自我清除)和读取从它在一个单独的线程?

Looking at the design, I don't see why you need so many buffers. There appears to be one thread and two buffers too many. Why not just have one ring buffer, fill that up (it's 'self purging') and read from it in a separate thread? Is the design yours (ie can be changed) or has it been imposed on you?

无论如何,请尝试为您的音频池使用环形缓冲区。

In any event, try using a ring buffer for your audio pool.

这篇关于实时清除数据容器的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆