Questions tagged [circular-buffer]

A circular buffer is a data structure that uses a single, fixed-size buffer as if it were connected end-to-end. This structure lends itself easily to buffering data streams.

A circular buffer (AKA cyclic buffer, ring buffer, or circular queue) is a data structure that uses a single fixed-size buffer as if it were connected end-to-end. This structure lends itself easily to buffering data streams.

The circular buffer uses two pointers to indicate the current beginning and ending of the data on the buffer. The old/"First In" data is deleted from the buffer as it is read, moving forward the beginning pointer. New data is added at the end of the buffer (moving forward the corresponding pointer). The buffer physical storage is the same during all the operation if the reading speed is faster than the data acquisition process.

The useful property of a circular buffer is that it does not need to have its elements shuffled around when one is consumed. (If a non-circular buffer were used then it would be necessary to shift all elements when one is consumed.) In other words, the circular buffer is well suited as a FIFO (first in first out) buffer while a standard, non-circular buffer is well suited as a LIFO (last in first out) buffer.

Circular buffering makes a good implementation strategy for a queue that has fixed maximum size. Should a maximum size be adopted for a queue, then a circular buffer is a completely ideal implementation; all queue operations are constant time. However, expanding a circular buffer requires shifting memory, which is comparatively costly. For arbitrarily expanding queues, a Linked list approach may be preferred instead.

Check http://en.wikipedia.org/wiki/Circular_buffer for more information.

417 questions
1
vote
1 answer

Strategies to mitigate polling effects in ring buffers

I am using a canonical ring buffer implementation in a 1Reader thread/1Writer thread setting. Since the reader loops when the buffer is empty [the writer loops when the buffer is full] and continously polls the control variables, I call…
ziu
  • 2,634
  • 2
  • 24
  • 39
1
vote
2 answers

Is there a way to create a circular file storage ? like syslog in linux

In my iOS application, I want to store some messages that I obtain from my remote server. However, instead of storing these messages forever, I want to purge, once I have a N number of messages; i.e., if my N is configured to be 10, I want to store…
Sankar
  • 6,192
  • 12
  • 65
  • 89
0
votes
3 answers

swith to circular list to shift easier

I have a private arraylist with classes that include two longs, a float and a BigDecimal. As new data comes in I currently am removing the oldest element, shifiting all other elements over, and then adding the newest element. I think this is taking…
0
votes
1 answer

c++ boost iterator throwing assert and programme terminates

I get the following error at this line: const short pcmSample = *reinterpret_cast(*(buffer->index)); buffer is an object of class accumlator. Here I am trying to convert a byte array into shorts. The code throws this runtime error and…
ken
  • 816
  • 1
  • 9
  • 25
0
votes
2 answers

How to implement RingFiFoBuffer

I'm new to Java programming. I have several questions about how to implement RingFiFoBuffer: Can I store big XML files into this buffer? If yes how big? Can several threads insert/delete/fetch records from the RingBuffer simultaneously? How many…
Peter Penzov
  • 1,126
  • 134
  • 430
  • 808
0
votes
1 answer

Circular (ring or cyclic) buffers in hardware: possible usage in microprocessors?

It is known that circular buffers are a useful part of DSP's like made by TI for efficient video or sound data processing. Are there possible uses of these buffers in general type microprocessors like CPU's made by Intel or AMD?
val
  • 323
  • 2
  • 8
  • 20
0
votes
2 answers

rear value not working properly in circular array queue

I have this code for adding: public void add(AnyType item){ if(isEmpty()){ q[f]=item; } else{ if(size==q.length){ AnyType[] copyQ = (AnyType[]) new Object[q.length*2]; System.arraycopy(q, f, copyQ,…
randomizertech
  • 2,309
  • 15
  • 48
  • 85
0
votes
0 answers

mpmc ring buffer: Does a back-off improve the throughput?

Assume having a bounded MPMC queue (roughly something like this: https://www.1024cores.net/home/lock-free-algorithms/queues/bounded-mpmc-queue). N threads are producers and M threads are consumers. All producers and consumers run on isolated cores…
Kevin Meier
  • 2,339
  • 3
  • 25
  • 52
0
votes
1 answer

How to speed up data imports from ring buffers in a java client?

We have a third party application producing data at a very high speed and storing it in multiple ring buffers (hazelcast cluster). The consumer application (another third party app) uses this java hazelcast library to read ring buffer data. It calls…
Andy Dufresne
  • 6,022
  • 7
  • 63
  • 113
0
votes
0 answers

Ring buffers of android logcat

The result of data below is from "adb logcat -d -b V:*". As I know, each of ring buffers - 'main, system, crash, events, radio is separate. But as you can see, log data is continuous. How can I explain them? --------- beginning of events 06-25…
SimDDang
  • 1
  • 1
0
votes
0 answers

How to implement circular buffer using memcpy in C

I am a beginner programming in C and just starting to work with circular buffers. I have implemented this code and need to adapt the queue and dequeue functions to use memcpy(). Does anyone know the correct way to implement it? #define BUFFER_SIZE…
JGS96
  • 1
0
votes
2 answers

Lock-free ring buffer designs: Non-atomic + errors seen, atomic + opinions sought

seeking advice and opinions about two different lock-free ring buffer designs. Notes: The following is being tested on Intel 64-bit i5, on Linux. Only one thread is writing and only one thread is reading during these tests. Parts of our application…
0
votes
1 answer

Why use the circular buffer in "overriding" mode at all?

I have been trying to wrap my head around the modes of operations for the circular buffer data structure. It seems trivial that it works for a consumer-producer architecture where a consumer reads data a producer wrote earlier. In this case, it…
John C.
  • 405
  • 5
  • 19
0
votes
1 answer

circular array class in python

I have a project to create a circular array class, and the language I will be using is python. I am new to classes in python, but after reading through some webpages and chapters in books I think I have an understanding of how they work. However I…
roboman
  • 13
  • 6
0
votes
1 answer

Appropriate Data structure for Sequential access but Random Insertion/Deletion

If i'm writing an algorithm that requires storage of data that will be sequentially accessed from the first item in the list to the last item in the list. And that Data will regularly need to be inserted or deleted at random locations anywhere in…