My problem is best explained by the architecture below
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?
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)
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.