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

c circular buffer with constant time delay for mpeg-ts

Could You say me the best way of implementing circular buffer with constant time delay between input and output in c on linux. I write to the buffer in on thread and read it on another. I need to save constant time difference between read and write,…
ostryck
  • 13
  • 2
-1
votes
1 answer

How can I convert my circular array into a String?

I have a class ArrayDeque where I take in a circular array and I'm trying to implement a function turntoString() to turn my Array into a string. I'm currently stumped on how can I do this due to the fact that this is a circular array. Here is my…
Droid
  • 520
  • 1
  • 7
-1
votes
2 answers

C Simple RingBuffer - Multithreading - Finding Critical Sections

so I wrote a simple C Ring Buffer that I'm now testing using multiple threads and I'm having a hard time trying to get the code to fail so that I can identify critical sections. Note: The code is in C, but i'm testing it in C++ files because its…
-1
votes
1 answer

Implementing Circular Buffer in C, getting undefined behavior

I'm back, and it appears I still haven't quite figured out memory management in C. While trying to design an event queue I decided to build a circular buffer as an exercise. After a bit of research I am trying to model it after the following…
user3407513
  • 45
  • 1
  • 1
  • 7
-1
votes
2 answers

How to write strings and integers in a ring buffer?

How to write strings and integers in a ring buffer? I would like to write multiple strings and integers into the ring buffer but my c++ knowledge is limited. If you need some more info, please let me know. I appreciate any help that you can provide.…
-1
votes
2 answers

circular buffer using mutex

This was from compsci lecture quiz that my professor want us to challenge. he said that this class is about circular buffer but has got major problem. I've try to think for whole day but have no clue. please give me some ideas #include…
user842589
  • 107
  • 2
  • 12
-1
votes
2 answers

Circular buffer writing randomly terminates the program?

"The program has unexpectedly finished." I have a class that is calling CMem::Write(). And it Displays the iteration to the screen. Sometimes it reaches 140, others... 12, 3, 42, falls out right away... very random. If I remove the call to …
jdl
  • 6,151
  • 19
  • 83
  • 132
-2
votes
1 answer

Atomic operation on the circular global buffer in cuda

I am implementing a circular global memory to enable all threads read/write data to the same buffer simultaneously. It is a very simple producer/consumer algorithm in cpu. But i found something wrong in my cuda code. The circular buffer was defined…
Jannus YU
  • 89
  • 6
-2
votes
1 answer

Circular Array Issue

I'm stuck on a method right now. I need to write a method, public boolean equals(CircularArray m) which test whether two FIFO queues implemented as circular arrays have the same elements in the same order. For example, suppose that c and d are…
JerryCrowley
  • 145
  • 1
  • 12
-3
votes
2 answers

Circular Char Array Buffer - c

I am using a char * array to make a buffer to move information from multiple mapping threads to a reducing thread. I need to make the array circular, however, i keep getting segmentation faults when the array runs out of room. How do I make the…
-4
votes
2 answers

How to solve this with a circular buffer?

What is the most efficient way of accomplishing the insertion of one element before others in an array without having to rearrange all elements with a for loop. I have tried a circular buffer implementation, but it doesn't work and I am getting…
neolith
  • 699
  • 1
  • 11
  • 20
-6
votes
1 answer

Java Generics Question

Queue12 is an interface, QueueImp12 is an implementation of Queue12. So i'm trying to test my QueueImp12 but when i run it(it compiles) in eclipse my output gets terminated in console. I believe I created ringBuffer correctly. If my test looks fine,…
earbulan
  • 37
  • 4
1 2 3
27
28