]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/libstdc++-v3/contrib/libstdc++-v3-4.7/doc/html/manual/bk01pt03ch20s02.html
update
[l4.git] / l4 / pkg / libstdc++-v3 / contrib / libstdc++-v3-4.7 / doc / html / manual / bk01pt03ch20s02.html
1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml"><head><title>Design Issues</title><meta name="generator" content="DocBook XSL-NS Stylesheets V1.76.1"/><meta name="keywords" content="&#10;      ISO C++&#10;    , &#10;      allocator&#10;    "/><meta name="keywords" content="&#10;      ISO C++&#10;    , &#10;      library&#10;    "/><meta name="keywords" content="&#10;      ISO C++&#10;    , &#10;      runtime&#10;    , &#10;      library&#10;    "/><link rel="home" href="../index.html" title="The GNU C++ Library"/><link rel="up" href="mt_allocator.html" title="Chapter 20. The mt_allocator"/><link rel="prev" href="mt_allocator.html" title="Chapter 20. The mt_allocator"/><link rel="next" href="bk01pt03ch20s03.html" title="Implementation"/></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Design Issues</th></tr><tr><td align="left"><a accesskey="p" href="mt_allocator.html">Prev</a> </td><th width="60%" align="center">Chapter 20. The mt_allocator</th><td align="right"> <a accesskey="n" href="bk01pt03ch20s03.html">Next</a></td></tr></table><hr/></div><div class="section" title="Design Issues"><div class="titlepage"><div><div><h2 class="title"><a id="allocator.mt.design_issues"/>Design Issues</h2></div></div></div><div class="section" title="Overview"><div class="titlepage"><div><div><h3 class="title"><a id="allocator.mt.overview"/>Overview</h3></div></div></div><p> There are three general components to the allocator: a datum
4 describing the characteristics of the memory pool, a policy class
5 containing this pool that links instantiation types to common or
6 individual pools, and a class inheriting from the policy class that is
7 the actual allocator.
8 </p><p>The datum describing pools characteristics is
9 </p><pre class="programlisting">
10   template&lt;bool _Thread&gt;
11     class __pool
12 </pre><p> This class is parametrized on thread support, and is explicitly
13 specialized for both multiple threads (with <code class="code">bool==true</code>)
14 and single threads (via <code class="code">bool==false</code>.) It is possible to
15 use a custom pool datum instead of the default class that is provided.
16 </p><p> There are two distinct policy classes, each of which can be used
17 with either type of underlying pool datum.
18 </p><pre class="programlisting">
19   template&lt;bool _Thread&gt;
20     struct __common_pool_policy
21
22   template&lt;typename _Tp, bool _Thread&gt;
23     struct __per_type_pool_policy
24 </pre><p> The first policy, <code class="code">__common_pool_policy</code>, implements a
25 common pool. This means that allocators that are instantiated with
26 different types, say <code class="code">char</code> and <code class="code">long</code> will both
27 use the same pool. This is the default policy.
28 </p><p> The second policy, <code class="code">__per_type_pool_policy</code>, implements
29 a separate pool for each instantiating type. Thus, <code class="code">char</code>
30 and <code class="code">long</code> will use separate pools. This allows per-type
31 tuning, for instance.
32 </p><p> Putting this all together, the actual allocator class is
33 </p><pre class="programlisting">
34   template&lt;typename _Tp, typename _Poolp = __default_policy&gt;
35     class __mt_alloc : public __mt_alloc_base&lt;_Tp&gt;,  _Poolp
36 </pre><p> This class has the interface required for standard library allocator
37 classes, namely member functions <code class="code">allocate</code> and
38 <code class="code">deallocate</code>, plus others.
39 </p></div></div><div class="navfooter"><hr/><table width="100%" summary="Navigation footer"><tr><td align="left"><a accesskey="p" href="mt_allocator.html">Prev</a> </td><td align="center"><a accesskey="u" href="mt_allocator.html">Up</a></td><td align="right"> <a accesskey="n" href="bk01pt03ch20s03.html">Next</a></td></tr><tr><td align="left" valign="top">Chapter 20. The mt_allocator </td><td align="center"><a accesskey="h" href="../index.html">Home</a></td><td align="right" valign="top"> Implementation</td></tr></table></div></body></html>