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).
Or read this on Hacker News