开发者

most efficient data storage object for queuing a max number of elements

I need a storage type that I can set a max number of elements for and whenever I add something to the tail, the head is truncated as necessary with low overhead. I can of course do this manually if I have to. Example

max = 1000

fill it with integers 1-1000 : [1,2,...,999,1000]

add numbers 1000 - 1500 : [500,501,....,1499,1500]

It has to be as cheap an operation as possible since I will be running multiple threads at this time, one doing audio recording. I don't care a开发者_运维百科bout keeping the head elements as they are popped off, I would like to get rid of them in a bulk operation.

I checked out the queue types in the SDK, not sure which could suit these needs, possibly a linked queue of some kind.

Thanks for any help


Use a ring buffer, also known as a circular queue; these can be implemented as arrays, so they're particularly cheap. See this question for an implementation in Java.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜