As I understand, deque is a cyclic buffer, and when it runs out of space, it allocates new space (if it cans). Is there a way to limit the deque can grow to?
Or the only way to make sure it doesn’t grow over maximum size is to check every time I want to insert data to deque?
As I understand, deque is a cyclic buffer, and when it runs out of
Share
Yes, as with every STL collection, one of the templated parameters is an allocator.
So you can write your own custom allocator that will keep a track of the memory and throw
bad_allocif you exceed this limit, even if the memory is available.Incidentally, a
std::dequeis usually implemented as a collection of “pages” where each page contains a fixed number of elements.If you want a circular buffer implementation where you can insert or delete “anywhere”,
std::dequewould not be the most efficient to use,std::listwould be (although there are circular collections available in boost you could use).