• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2<html>
3<head>
4<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5<title>Rationale</title>
6<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
7<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
8<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
9<link rel="up" href="../circular_buffer.html" title="Chapter 8. Boost.Circular Buffer">
10<link rel="prev" href="example.html" title="Circular_buffer example">
11<link rel="next" href="implementation.html" title="Implementation">
12</head>
13<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
14<table cellpadding="2" width="100%"><tr>
15<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
16<td align="center"><a href="../../../index.html">Home</a></td>
17<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
18<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
19<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
20<td align="center"><a href="../../../more/index.htm">More</a></td>
21</tr></table>
22<hr>
23<div class="spirit-nav">
24<a accesskey="p" href="example.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../circular_buffer.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="implementation.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
25</div>
26<div class="section">
27<div class="titlepage"><div><div><h2 class="title" style="clear: both">
28<a name="circular_buffer.rationale"></a><a class="link" href="rationale.html" title="Rationale">Rationale</a>
29</h2></div></div></div>
30<p>
31      The basic motivation behind the <code class="computeroutput"><a class="link" href="../boost/circular_buffer.html" title="Class template circular_buffer">circular_buffer</a></code>
32      was to create a container which would <span class="bold"><strong>work seamlessly
33      with STL</strong></span>.
34    </p>
35<p>
36      Additionally, the design of the <code class="computeroutput"><a class="link" href="../boost/circular_buffer.html" title="Class template circular_buffer">circular_buffer</a></code>
37      was guided by the following principles:
38    </p>
39<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
40<li class="listitem">
41          Maximum <span class="emphasis"><em>efficiency</em></span> for envisaged applications.
42        </li>
43<li class="listitem">
44          Suitable for <span class="emphasis"><em>general purpose use</em></span>.
45        </li>
46<li class="listitem">
47          The behaviour of the buffer as <span class="emphasis"><em>intuitive</em></span> as possible.
48        </li>
49<li class="listitem">
50          Suitable for <span class="emphasis"><em>specialization</em></span> by means of adaptors.
51          (The <code class="computeroutput"><a class="link" href="../boost/circular_idm45227212366288.html" title="Class template circular_buffer_space_optimized">circular_buffer_space_optimized</a></code>
52          is such an example of the adaptor.)
53        </li>
54<li class="listitem">
55          Easy to <span class="emphasis"><em>debug</em></span>. (See Debug Support for details.)
56        </li>
57</ul></div>
58<p>
59      In order to achieve maximum efficiency, the <code class="computeroutput"><a class="link" href="../boost/circular_buffer.html" title="Class template circular_buffer">circular_buffer</a></code>
60      and <code class="computeroutput"><a class="link" href="../boost/circular_idm45227212366288.html" title="Class template circular_buffer_space_optimized">circular_buffer_space_optimized</a></code>
61      store their elements in a <span class="bold"><strong>contiguous region of memory</strong></span>,
62      which then enables:
63    </p>
64<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
65<li class="listitem">
66          Use of fixed memory and no implicit or unexpected memory allocation.
67        </li>
68<li class="listitem">
69          Fast constant-time insertion and removal of elements from the front and
70          back.
71        </li>
72<li class="listitem">
73          Fast constant-time random access of elements.
74        </li>
75<li class="listitem">
76          Suitability for real-time and performance critical applications.
77        </li>
78</ul></div>
79<p>
80      Possible applications of the circular buffer include:
81    </p>
82<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
83<li class="listitem">
84          Storage of the <span class="emphasis"><em>most recently received samples</em></span>, overwriting
85          the oldest as new samples arrive.
86        </li>
87<li class="listitem">
88          As an underlying container for a <span class="emphasis"><em>bounded buffer</em></span> (see
89          the Bounded Buffer example, code at <a href="../../../libs/circular_buffer/example/circular_buffer_bound_example.cpp" target="_top">circular_buffer_bound_example.cpp</a>).
90        </li>
91<li class="listitem">
92          A kind of <span class="emphasis"><em>cache</em></span> storing a specified number of last
93          inserted elements.
94        </li>
95<li class="listitem">
96          Efficient fixed capacity <span class="emphasis"><em>FIFO (First In, First Out)</em></span>,
97        </li>
98<li class="listitem">
99          Efficient fixed capacity <span class="emphasis"><em>LIFO (Last In, First Out)</em></span>
100          queue which removes the oldest (inserted as first) elements when full.
101        </li>
102</ul></div>
103</div>
104<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
105<td align="left"></td>
106<td align="right"><div class="copyright-footer">Copyright © 2003-2013 Jan Gaspar<p>
107        Distributed under the Boost Software License, Version 1.0. (See accompanying
108        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
109      </p>
110</div></td>
111</tr></table>
112<hr>
113<div class="spirit-nav">
114<a accesskey="p" href="example.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../circular_buffer.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="implementation.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
115</div>
116</body>
117</html>
118