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
0
votes
1 answer

Circular buffer for recording seconds before and after trigger using MediaCapture c#

I'm looking for an example of how to create a circular buffer using MediaCapture to record seconds before a trigger and after, something similar to Raspberry Pi's picamera.PiCameraCircularIO(camera, seconds=clip_length). I am creating a UWP app,…
Chris
  • 27
  • 7
0
votes
1 answer

GNU Radio circular buffer manipulation

I encountered the following error gr::log :WARN: tpb_thread_body - asynchronous message buffer overflowing, dropping message Out of serendipity, I ran into this GNU Radio presentation on Youtube. The presenter mentioned an OOT block he called…
0
votes
0 answers

Error in storing outer class object in inner class C++

I was implementing the ring buffer and have encountered an error. What does it mean to store a reference of outer class(class ring) object(m_ring) in inner class(class iterator) and when I remove the reference(&) the program compiles correctly but…
Michelle
  • 97
  • 1
  • 10
0
votes
2 answers

AudioUnit noise if there is no output buffer

I am trying to implement playing pcm audio received from remote server via socket. Here was my previous question link. This works fine as I use circular buffer to always feed in the incoming buffer. However I have a problem that there is a huge…
akaiz
  • 131
  • 11
0
votes
1 answer

Size of pointer inside a struct

So, I have this structure used to implement a circular buffer of another structure (plane) typedef struct queue { struct plane *q; int size, capacity, front, rear; }queue; After this I declare the structure queue *q; and later,…
0
votes
3 answers

Java generic circular buffer sort

I have an assignment to implement a generic circular buffer. Everything is fine, I only need to do a sort method however I cannot think of a solution to make it generic. Could you please give me a hint? Thank you! public class CircularBuffer
Kokufuu
  • 145
  • 1
  • 2
  • 7
0
votes
0 answers

Circular Buffer Reader, I'm stuck

I am trying to implement a circular buffer, I'm writing to it just fine, all the received data is there, but something about my function to read from it doesn't work. No data gets saved into MtoHSdata. The data I'm trying to read has a Start (>) and…
Kater
  • 63
  • 10
0
votes
1 answer

NodeJS Firebase Circular Buffer or Queue

I am using Firebase with Nodejs. I want to limit number of records inbattleReports by number N. But not just limit. If new data will come and there is already N records in battleReports, delete oldest one and add new one. I want to implement…
tprieboj
  • 1,680
  • 6
  • 31
  • 54
0
votes
1 answer

GPS UART data written multiple times to Buffer

I am receiving/reading data from a GPS module sent via USART3 to the STM32F091. The data gets there just fine which I confirm by sending it to my PC COM3 port and feeding it to 'u-center' (GPS evaulation software). My problem is that I want to…
Kater
  • 63
  • 10
0
votes
2 answers

implementing a circular queue in python - a level standard

i am trying to implement a circular queue in python and my current program keeps giving me error, and I would like to know the problem and solve it. my current program is : # circular queue class circularQueue: def __init__(self, maxsize): …
0
votes
1 answer

circular buffer for opencv cv::Mat

I use this example for circular buffering. To test test I created next three functions: void cnt(ScreenStreamer &SS, cv::Mat & img) { CVUtils::Image m_img; SS >> m_img; img = m_img.matRef(); cv::imshow("",img); …
hagor
  • 304
  • 1
  • 15
0
votes
1 answer

How is the global variable being incremented when it's not being directly specified?

I'm working on a small project where I'm implementing a queue as a circular array. As a challenge, I was assigned to not use any list functions like append when implementing this ADT. It's assumed that I only need to resize the queue when it gets…
Kevin Le
  • 49
  • 2
  • 9
0
votes
0 answers

circular queue pointer f value?

I have been struggling with this question in my data structures textbook. I know how the f and r pointers in circular queue works, however, I am having a bit of a trouble cracking this question in my text book. I would be grateful if someone can…
0
votes
2 answers

Is there a way to keep the front of an empty boost circular buffer hot in cache?

There is a specific circular buffer I wish to keep hot in cache, however it can go unused for extended periods of time. This is causing cache misses. I have an idle loop that can take responsibility for keeping the location hot, but I cannot see a…
Chuu
  • 4,301
  • 2
  • 28
  • 54
0
votes
0 answers

Circular queue with a struct

I'm trying to code a circular list but I have to add more than one information to each element of the list. My queue is defined as typedef struct queue { int data[maxsize]; int f,r; }myQueue; myQueue q And I need each element to be a…
paragon
  • 15
  • 5