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