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

C++ how to define the operator [] to write and read an item of the circular buffer

I have created a template class that implement a circular buffer. The buffer is formed of items that have a value of type T. I want to define the operator[ ] to write and read an element of the buffer. Even when I try to read an element already…
0
votes
0 answers

C: Multi producer, multi consumer bounded queue

I try (better tried) to implement a circular buffer with the following interface: ring_buffer *ring_buffer_create(int capacity, int element_size); void ring_buffer_destroy(ring_buffer *buffer) const void *ring_buffer_read_acquire(ring_buffer…
Kevin Meier
  • 2,339
  • 3
  • 25
  • 52
0
votes
0 answers

DPDK implementation of MPSC ring buffer

While going through the implementation of the DPDK MPSC (multi-produce & single-consumer) Ring Buffer API, i found the code to move the head of the producer for inserting new elements in the Ring buffer. The function is as follows : static…
Prateek
  • 11
  • 3
0
votes
1 answer

Conway's Game Of Life: Why patterns behave incorrectly?

I'm trying to create an implementation of Conway's Game of Life in Lua. The game field is a bidimensional circular table with 100 rows and 47 columns (4700 cells total), where a cell can have a value of 1 (alive) or 0 (dead). The problem is when I…
0
votes
3 answers

Unity array, get current index -x or +x

How I can achieve getting the current index -5 for example. I know how to get the current index and I can subtract or add to that index, but this will cause Array out of bounds errors. Let's say the array has 15 items (index 0/14) and my current…
Quincy Norbert
  • 431
  • 1
  • 6
  • 18
0
votes
1 answer

C# RTSP & VLC dotnet

I'm working with C# and VLC library, and I wonder if there is way to get hands to VLC buffer (netwoking-cache or so). What I could use, is to save that to my own circular buffer and save it IF needed. Is this possible, or should I just do it with…
JubinBlack
  • 353
  • 1
  • 2
  • 6
0
votes
2 answers

thread safe random access circular array in java?

I need to cache the least recent result (say 10,000) of a concurrent system, and random access them. Since most of concurrent cache are based on linked list, I'm wondering if there is a thread safe random access circular array in java?
los
  • 61
  • 5
0
votes
1 answer

Circular Buffer: Selecting Range of Indices that Include the Wraparound Point

I think this question is best understood with an example. So here we go: Imagine the following are defined: parameter number_of_points_before_point_of_interest = 4; logic [15:0] test_data = 16'b0000111100001111; logic [3: 0]…
Mas
  • 21
  • 5
0
votes
1 answer

How to iterate from head to tail in circular buffer without branching

I have a following problem and despite many approached all fail to satisfy my needs: Having a circular buffer where index is size_t and underlying buffer may be anything I please, I need to iterate both forward and backwards like so: from head to…
0
votes
0 answers

How to resolve error: 'boost::circular_buffer >::iterator' is not a type?

I am trying to pass boost::circular_buffer::iterator as a function argument to iterate over the circular buffer. This is the prototype definition of a function in a header file inside the project that I am working…
Taki Eddine
  • 33
  • 1
  • 5
0
votes
0 answers

Simple Circular list

Here's my idea on how to manage a simple circular buffer using arraylist. I've looked around and all the other circular lists seem overly complicated. If you don't worry about things like sorted lists then I think this is better, but I would like to…
Bugz
  • 118
  • 1
  • 9
0
votes
1 answer

Reorder Buffer: Pointer values when it is full?

The re-order buffer used in the Tomasulo's algorithm for out-of-order execution and branch speculation has 2 pointers. Head pointer: Points to the oldest instruction. This will be the next instruction to be committed. Tail pointer: Points where…
0
votes
0 answers

Feed data from file into Ring buffer efficiently

I have searched around on the internet and there were few document about how we use Ring Buffer to read from file or write to a file. So i wrote my own implementation here: my ringbuffer structure typedef struct Ringbuffer { char* buffer; …
Van Teo Le
  • 164
  • 3
  • 11
0
votes
1 answer

Create a simple forward iterator which automatically wraps at the "end" of a circular buffer

I've created a simple circular buffer by inheriting std::vector and overloading its operator[] to modulo the desired index with the vector size: template class circvector : public std::vector { public: T& operator[](size_t index)…
NKatUT
  • 429
  • 3
  • 10
0
votes
0 answers

Question in Book Linux device driver 3rd about interrupt handler for circular buffer

I am reading LLDR3, having a question on P.271 in section "Implementing a Handler" Bottom are codes I am having questions: I see writer ( ISR ) and reader ( which is waken-up by ISR ) they are touching on same buffer ( short_queue ), since they are…