Get the latest tech news

What's in a ring buffer? And using them in Rust


Monday, February 10, 2025 Working on my cursed MIDI project, I needed a way to store the most recent messages without risking an unbounded amount of memory usage. I turned to the trusty ring buffer for this! I started by writing a very simple one myself in Rust, then I looked and what do you know, of course the standard library has an implementation.

Working on my cursed MIDI project, I needed a way to store the most recent messages without risking an unbounded amount of memory usage. In a regular old buffer, if you use it as a queue—add to the end, remove from the front—then you'll eventually need to either reallocate the entire thing or shift all the elements over. This implements a ring buffer, and the name comes from "Vec" (Rust's growable array type) combined with "Deque" (a double-ended queue).

Get the Android app

Or read this on Hacker News

Read more on:

Photo of Rust

Rust

Photo of ring buffer

ring buffer

Related news:

News photo

Build your own SQLite in Rust, Part 5: Evaluating queries

News photo

Greg Kroah-Hartman Makes A Compelling Case For New Linux Kernel Drivers To Be Written In Rust

News photo

Parsing JSON in 500 lines of Rust