Why is the circular buffer not standardized in C++?
Asked Answered
O

0

12

I want to know the history of the standardization of the circular buffer(circular queue or deque).

AFAIK, the current C++ standard(C++ 2023) doesn't provide a circular buffer in the STL. I googled and found only one proposal, ring_span around 2015. Boost has the circular_buffer. Some provide in-house implementations, such as cqueue.

If you repeat push and pop operations with a std::deque, you repeat allocating and freeing heap blocks. In Qt(one of largest C++ projects), the situation is worse, where QQueue keeps allocating heap blocks(and never freeing).

I'm not asking for opinions. I want to know the history. I expect good reasons why it was so hard to standardize the circular buffer.

Overrun answered 8/8, 2023 at 2:39 Comment(9)
What exactly are you asking for? Boost.CircularBuffer has a fixed capacity. You can change the capacity, but insertions by themselves don't do that.Haphtarah
In my experience, every time I want a ring buffer for something, I need to implement it a little differently from the last time. I'm not convinced that standardizing it would change this, and if it did something like throw an exception when pushing onto a full queue, there's a good chance I'd never use it.Eloyelreath
@NicolBolas, thanks for a fast feedback. I'm asking on the history. I said the history of what I found - only one proposal(P0059). Is this right? (I'm a novice on the history of C++ specification.) Then, IMHO, there must be a good reason why there are so few proposals and why they were not accepted. Maybe I'm too curious. But I'm very interested on the history of a certain programming feature.Overrun
The proposal paper has an email address, you could ask the P0059R4' author directly. He might be the only knowing the true answer.Nagy
This is my impression: Because circular buffer is an underrated data structure. And yes, as @Eloyelreath said there are too many details and variants to agree on one, flexible vs fixed, allocating vs. not. Also, it doesn't fit with the framework of 1D containers, as push means also pop, so the discussions about the interface would be endless. Just some theories.Verine
Here you have a few tidbits: quuxplusone.github.io/blog/2018/05/30/…Beryl
For something to enter the standard a large number of people on the committee need to agree on it's specification. For something like a circular buffer which is likely to mostly be used in performance critical applications that specification is likely to be highly application specific and finding one specification that fits most use cases and everyone can agree on is very difficultMidwest
It does not help making the specification simpler that often different threads push and pop and should not block each other, when doing so.Beryl
I don't buy "there are too many variants". Rust has a circular buffer in its standard library and it's great and has a very obvious API. Perhaps the real question is "why isn't std::deque a ring buffer?"Parlous

© 2022 - 2024 — McMap. All rights reserved.