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

Add class containing a circular buffer to Vector

I am trying to create a vector filled with class objects, and the class objects contain circular buffers as one of their members. I am running into this error: In file included from .pio/libdeps/teensy40/Vector/src/Vector.h:95:0, …
0
votes
1 answer

O(1) JavaScript Circular Buffer With GetMax and GetMin

So I've been scouring the web to find a way to do this but nothing I've found fits the exact solution we are looking for. I have an app that stores float numbers in a circular buffer. The circular buffer class can be found here…
ccx105
  • 1
  • 1
0
votes
0 answers

Processing queue with asyncio only fires after all items are placed in queue using asyncio in python

I am trying to create some code in python that will put data from a generator (currently a simple counting loop but will be a sensor data at some point) and place it in a queue. Once in a queue i want to pull data off it and send it over a TCP…
0
votes
1 answer

Logger library in C for embedded system using circular(ring) buffer implementation isn't working in the main file

So, I am trying to write my own logger API library for my embedded system. The embedded system is using bare metal programming without any OS. Hence, the logger library is a static library. The project is being built using CMake. The first goal of…
0
votes
1 answer

Writing audio stream to circular buffer but Segmentation error reading value

I very new concepts of audio processing and have a basic knowledge of C++, my end goal is to create a means to measure harmonic distortion on line-in audio; my thoughts are to write audio-in stream to a circular buffer, then read from the circular…
Alex2134
  • 557
  • 7
  • 22
0
votes
1 answer

Able to instantiate an object but not access its functions - 'Symbol(s) not found' error

I'm using the 'TPCircularBuffer' class for creating a circular buffer object, from this website. This is my current code: TPCircularBufferRecord bufferRecord; //1 TPCircularBufferInit(&bufferRecord, kBufferLength); //2 Line 1…
JimmyB
  • 326
  • 3
  • 12
0
votes
3 answers

How would YOU do/write this homework assignment? (theoretical)

I'm not asking for anyone to do this homework for me, but I bring it up because it's a very good practical introduction to C# and threading, but at the same time I feel it's perhaps a little too simple. Is this really the best way to teach…
Firoso
  • 6,647
  • 10
  • 45
  • 91
0
votes
0 answers

Troubles with implementing retroactive audio recording (save last X min instead of whole recoding) functionality to audio recording app Android Studio

Using TVAC Studio's tutorial, I built an app that records audio and saves the files in a list which can be played back within the app. My problem is that I want to continuously record and upon repressing the mic button, save the last X minutes…
0
votes
1 answer

blank image capture with opencv threading

I am trying to write the frame captured from my laptop camera in to a circular buffer. I wanted to create a thread to handle this task (in an asynchronous way). When i try to get the last frame stored with get_last() method and show it, black screen…
0
votes
1 answer

Circular buffer does not give the correct size of the buffer after 6-th element

I have written the code for the circular buffer in C and it works well until some extent. I took the size of the buffer being equal to 10. When I fill the buffer till element 6 - it works fine. But at the moment when I fill the 7-th element - I get…
Rostyslav
  • 85
  • 1
  • 1
  • 5
0
votes
1 answer

ArrayDeque operations

I am having some free time and trying to understand how ArrayDeque works internally. I've read a couple of articles and questions/answers here and I think I'm pretty close. I used debugging to follow the workflow and there is something that's…
0
votes
1 answer

right to left - increment after chain in return

I'm trying to build a single producer/single consumer lock-free thread safe ring buffer. Here's piece the code: #include struct RingBuffer { static constexpr size_t S = 2; int data[S]; size_t start = 0; size_t end =…
markzzz
  • 47,390
  • 120
  • 299
  • 507
0
votes
0 answers

Can a ring buffer be resized as per the size provided while preserving the elements in case of a decrease/increase in size?

I'm trying to modify a fixed size ring buffer structure (written in C++) so that it would be able to handle the resize as per the requirement. First of all, I would like to know if this scenario is really possible to achieve? Because I have read…
astrix91
  • 1
  • 1
0
votes
1 answer

Calculate the distances between elements in a circular array

people = ["James","COP","George","COP","Sam","Mac","Johnny","Karina"] cops = [(idx+1) for idx, val in enumerate(people) if val == "COP"] #cops' positions peoplePositions = [(x+1) for x in range(len(people))] #index positions distances = [] for x…
Inovaula
  • 49
  • 9
0
votes
2 answers

Write a CircularBuffer (swift-nio) to a file in Swift using OutputStream?

I am trying to use a CircularBuffer from SwiftNIO to store data and once the buffer is almost full dump the contents to a file using an OutputStream. Unfortunately, the OutputStream.write() method takes UnsafePointer as an argument, while the…
jiko
  • 146
  • 1
  • 9