Home | Projects | Notes > Data Structures & Algorithms > Ring Buffer

Ring Buffer

 

Introduction

A ring buffer is a fixed-size data structure that uses a single, contiguous block of memory as a circular queue. It maintains two indices (front and back) to manage reading and writing. When the end of the buffer is reached, it wraps around to the beginning — forming a logical circle.

Pros:

Cons:

 

Implementation (C++)

Header (rbuffer.hpp)

Source (rbuffer.cpp)

Test Driver

 

Implementation (C)

Header (rbuffer.h)

Source (rbuffer.c)

Test Driver