Space Optimized Circular Buffer Container Adaptor

circular_buffer_space_optimized<T, Alloc>

Contents

   Synopsis
   Rationale
   Definition
   Template Parameters, Members and Friend Functions
   Model of
   Type Requirements
   Semantics
   See also
   Acknowledgments


Synopsis

The circular_buffer_space_optimized container is an adaptor of the circular_buffer. The functionality of the circular_buffer_space_optimized is similar to the base circular_buffer except it does not allocate memory at once when created rather it allocates memory as needed. (The predictive memory allocation is similar to typical std::vector implementation.) Moreover the memory is automatically freed as the size of the container decreases.

Figure: The memory allocation process of the space optimized circular buffer. The min_capacity represents the minimal guaranteed amount of allocated memory. The allocated memory will never drop under this value. By default the min_capacity is set to 0.


Rationale

The auto-resizing mode of the space optimized circular buffer can be useful in situations when the container can possibly store large number of elements but most of its lifetime the container stores just few of them. The usage of the circular_buffer_space_optimized will result in decreased memory consumption and can improve the CPU cache effectiveness.


Definition

#include <boost/circular_buffer.hpp>

In fact the circular_buffer_space_optimized is defined in the file boost/circular_buffer/adaptor.hpp, but it is necessary to include the boost/circular_buffer.hpp in order to use this container. Also, there is a forward declaration for circular_buffer_space_optimized in the header boost/circular_buffer_fwd.hpp.


Template Parameters, Members and Friend Functions

Template parameters, members and friend functions of the circular_buffer_space_optimized are almost the same as for the base circular_buffer. Refer the circular_buffer documentation and also its source code documentation for a detailed description.

The specific methods of the circular_buffer_space_optimized are listed below.

Method Description
circular_buffer_space_optimized(size_type capacity, size_type min_capacity = 0, const allocator_type& alloc = allocator_type()) Create an empty space optimized circular buffer with a given capacity.
circular_buffer_space_optimized (size_type capacity, size_type min_capacity, const T& item, const allocator_type& alloc = allocator_type()) Create a full space optimized circular buffer filled with copies of item.
template<InputIterator> circular_buffer_space_optimized(size_type capacity, size_type min_capacity, InputIterator first, InputIterator last, const allocator_type& alloc = allocator_type()) Create a space optimized circular buffer with a copy of a range.
min_capacity() const Return the minimal guaranteed amount of allocated memory.
set_min_capacity() Change the minimal guaranteed amount of allocated memory.


Model of

Random Access Container, Front Insertion Sequence, Back Insertion Sequence, Assignable (SGI), Equality Comparable, LessThan Comparable (SGI)


Type Requirements


Semantics

The behaviour of memory auto-resizing is as follows:

The semantics of the circular_buffer_space_optimized then follows the semantics of the base circular_buffer except the invalidation rules.

The rule for iterator invalidation for circular_buffer_space_optimized is as follows:


See also

boost::circular_buffer, std::vector


Acknowledgments

The idea of the space optimized circular buffer has been introduced by Pavel Vozenilek.


Copyright © 2003-2004 Jan Gaspar