From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2020-05-22 14:08:12
On 2020-05-22 14:32, Mathias Gaunard wrote:
> On Fri, 22 May 2020, 11:24 Andrey Semashev via Boost,
> <boost_at_[hidden] <mailto:boost_at_[hidden]>> wrote:
> circular_buffer is not a queue. The important difference is that it
> overwrites older elements as you keep pushing new elements into it.
> That's just the behaviour when you run out of capacity.
> Nothing prevents you from checking you're out of capacity and have
> different behaviour instead.
Yes, that is a possible workaround, but definitely not the intended use
of a circular buffer.
> As I said, the main advantage is avoiding dynamic memory allocations
> You cannot avoid memory allocations if your queue is unbounded.
> If pre-allocation of some size is a concern you can just use an adequate
One allocation might not be a problem, and small_ring_queue allows to
avoid even that, if the optimal capacity is known at compile time.
However, std::deque continues to dynamically allocate chunks as you push
and pop elements, even if the average number of enqueued elements stays
the same. This is avoided by ring queues.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk