-
Notifications
You must be signed in to change notification settings - Fork 1
/
MemArena.en.html
189 lines (175 loc) · 13.5 KB
/
MemArena.en.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<!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>MemArena — AMC Traffic Server Documentation</title>
<link rel="stylesheet" href="_static/sphinxdoc.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '8.0.x',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: '.txt'
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="RPC Refactor" href="RPC.en.html" />
<link rel="prev" title="Plugin Coordination" href="plugin-coordination.en.html" />
</head>
<body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="RPC.en.html" title="RPC Refactor"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="plugin-coordination.en.html" title="Plugin Coordination"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">SWOC Docs</a> »</li>
<li class="nav-item nav-item-1"><a href="ats-projects.en.html" accesskey="U">Traffic Server Projects</a> »</li>
</ul>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<p class="logo"><a href="index.html">
<img class="logo" src="_static/balcora-gate-400x400.jpg" alt="Logo"/>
</a></p>
<h3><a href="index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">MemArena</a><ul>
<li><a class="reference internal" href="#description">Description</a></li>
<li><a class="reference internal" href="#reference">Reference</a></li>
<li><a class="reference internal" href="#internals">Internals</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="plugin-coordination.en.html"
title="previous chapter">Plugin Coordination</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="RPC.en.html"
title="next chapter">RPC Refactor</a></p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/MemArena.en.rst.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<div><input type="text" name="q" /></div>
<div><input type="submit" value="Go" /></div>
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="memarena">
<span id="id1"></span><h1>MemArena<a class="headerlink" href="#memarena" title="Permalink to this headline">¶</a></h1>
<p><a class="reference internal" href="#_CPPv28MemArena" title="MemArena"><code class="xref cpp cpp-class docutils literal"><span class="pre">MemArena</span></code></a> provides a memory arena or pool for allocating memory. Internally the <a class="reference internal" href="#_CPPv28MemArena" title="MemArena"><code class="xref cpp cpp-class docutils literal"><span class="pre">MemArena</span></code></a> allocates memory in large blocks and allocates memory from these blocks. When <a class="reference internal" href="#_CPPv28MemArena" title="MemArena"><code class="xref cpp cpp-class docutils literal"><span class="pre">MemArena</span></code></a> is destructed all of the
memory blocks are deallocated. This is useful when the goal is to</p>
<ul class="simple">
<li>amortize allocation costs for many small allocations.</li>
<li>create better memory locality for containers.</li>
<li>deallocate memory in bulk.</li>
</ul>
<p><a class="reference internal" href="#_CPPv28MemArena" title="MemArena"><code class="xref cpp cpp-class docutils literal"><span class="pre">MemArena</span></code></a> has a mechanism for increasing locality by allowing coalescing the arena contents in to a single internal block of memory.</p>
<div class="section" id="description">
<h2>Description<a class="headerlink" href="#description" title="Permalink to this headline">¶</a></h2>
<p>When a <a class="reference internal" href="#_CPPv28MemArena" title="MemArena"><code class="xref cpp cpp-class docutils literal"><span class="pre">MemArena</span></code></a> is constructed it can be constructed with no allocated memory or an initial memory block of a
specific size. The <code class="xref cpp cpp-func docutils literal"><span class="pre">MemArena:reserve()</span></code> can specific the size of the next internally allocated block if internally
allocation should be delayed until <a class="reference internal" href="#_CPPv2N8MemArena5allocE6size_t" title="MemArena::alloc"><code class="xref cpp cpp-func docutils literal"><span class="pre">MemArena::alloc()</span></code></a> is called.</p>
<p>To support coalescence and compaction of memory for better locality, the methods <a class="reference internal" href="#_CPPv2N8MemArena6freezeE6size_t" title="MemArena::freeze"><code class="xref cpp cpp-func docutils literal"><span class="pre">MemArena::freeze()</span></code></a> and
<a class="reference internal" href="#_CPPv2N8MemArena4thawEv" title="MemArena::thaw"><code class="xref cpp cpp-func docutils literal"><span class="pre">MemArena::thaw()</span></code></a> are provided. Calling <a class="reference internal" href="#_CPPv2N8MemArena6freezeE6size_t" title="MemArena::freeze"><code class="xref cpp cpp-func docutils literal"><span class="pre">MemArena::freeze()</span></code></a> locks down all current blocks. After this call any further allocations will be in new internal memory blocks. The first internal block will be large enough to hold all of the currently allocated memory, unless a value is passed to <a class="reference internal" href="#_CPPv2N8MemArena6freezeE6size_t" title="MemArena::freeze"><code class="xref cpp cpp-func docutils literal"><span class="pre">MemArena::freeze()</span></code></a> to set the size explicitly. This enables copying all of the objects in the arena in to a single internal
block. Once this has been done calling <a class="reference internal" href="#_CPPv2N8MemArena4thawEv" title="MemArena::thaw"><code class="xref cpp cpp-func docutils literal"><span class="pre">MemArena::thaw()</span></code></a> will release the frozen memory blocks.</p>
<p>Other than a freeze / thaw cycle, there is no mechanism to release memory except for the destruction of the <a class="reference internal" href="#_CPPv28MemArena" title="MemArena"><code class="xref cpp cpp-class docutils literal"><span class="pre">MemArena</span></code></a>. This makes <a class="reference internal" href="#_CPPv28MemArena" title="MemArena"><code class="xref cpp cpp-class docutils literal"><span class="pre">MemArena</span></code></a> not suitable for a container that allocates variables sized objects (such as something like a <code class="code docutils literal"><span class="pre">Std::vector</span></code>). A container that allocates the same sized objects (such as a <code class="code docutils literal"><span class="pre">std::map</span></code>) can (and should) use a free list.</p>
</div>
<div class="section" id="reference">
<h2>Reference<a class="headerlink" href="#reference" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="_CPPv28MemArena">
<span id="MemArena"></span><em class="property">class </em><code class="descclassname"></code><code class="descname">MemArena</code><a class="headerlink" href="#_CPPv28MemArena" title="Permalink to this definition">¶</a><br /></dt>
<dd><dl class="function">
<dt id="_CPPv2N8MemArena8MemArenaEv">
<span id="MemArena::MemArena"></span><code class="descclassname"></code><code class="descname">MemArena</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv2N8MemArena8MemArenaEv" title="Permalink to this definition">¶</a><br /></dt>
<dd><p>Construct an empty arena.</p>
</dd></dl>
<dl class="function">
<dt id="_CPPv2N8MemArena8MemArenaE6size_t">
<span id="MemArena::MemArena__s"></span><code class="descclassname"></code><code class="descname">MemArena</code><span class="sig-paren">(</span><a class="reference internal" href="external-types.en.html#_CPPv26size_t" title="size_t">size_t</a> <em>n</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv2N8MemArena8MemArenaE6size_t" title="Permalink to this definition">¶</a><br /></dt>
<dd><p>Construct an arena with an initial internal block with at least <em>n</em> bytes of free space.</p>
</dd></dl>
<dl class="function">
<dt id="_CPPv2N8MemArena5allocE6size_t">
<span id="MemArena::alloc__s"></span>MemSpan <code class="descclassname"></code><code class="descname">alloc</code><span class="sig-paren">(</span><a class="reference internal" href="external-types.en.html#_CPPv26size_t" title="size_t">size_t</a> <em>n</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv2N8MemArena5allocE6size_t" title="Permalink to this definition">¶</a><br /></dt>
<dd><p>Allocate memory of size <em>n</em> bytes in the arena.</p>
</dd></dl>
<dl class="function">
<dt id="_CPPv2N8MemArena7reserveE6size_t">
<span id="MemArena::reserve__s"></span><a class="reference internal" href="#_CPPv28MemArena" title="MemArena">MemArena</a> &<code class="descclassname"></code><code class="descname">reserve</code><span class="sig-paren">(</span><a class="reference internal" href="external-types.en.html#_CPPv26size_t" title="size_t">size_t</a> <em>n</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv2N8MemArena7reserveE6size_t" title="Permalink to this definition">¶</a><br /></dt>
<dd><p>Mark the next internal block to have at least <em>n</em> bytes of available space.</p>
</dd></dl>
<dl class="function">
<dt id="_CPPv2N8MemArena6freezeE6size_t">
<span id="MemArena::freeze__s"></span><a class="reference internal" href="#_CPPv28MemArena" title="MemArena">MemArena</a> &<code class="descclassname"></code><code class="descname">freeze</code><span class="sig-paren">(</span><a class="reference internal" href="external-types.en.html#_CPPv26size_t" title="size_t">size_t</a> <em>n</em> = 0<span class="sig-paren">)</span><a class="headerlink" href="#_CPPv2N8MemArena6freezeE6size_t" title="Permalink to this definition">¶</a><br /></dt>
<dd><p>Freeze the existing internal memory blocks and do not allocate from them. If <em>n</em> is zero then for the next allocation request a block sufficiently large to hold all of the contents of the frozen memory will be created. If <em>n</em> > 0 the next internal allocation will have a least <em>n</em> bytes of available space.</p>
</dd></dl>
<dl class="function">
<dt id="_CPPv2N8MemArena4thawEv">
<span id="MemArena::thaw"></span><a class="reference internal" href="#_CPPv28MemArena" title="MemArena">MemArena</a> &<code class="descclassname"></code><code class="descname">thaw</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv2N8MemArena4thawEv" title="Permalink to this definition">¶</a><br /></dt>
<dd><p>Free frozen memory.</p>
</dd></dl>
</dd></dl>
</div>
<div class="section" id="internals">
<h2>Internals<a class="headerlink" href="#internals" title="Permalink to this headline">¶</a></h2>
<p>Each time a new internal block is needed, it should be larger than the previous block by either the square root of 2 or 2. It might be reasonable to use <code class="code docutils literal"><span class="pre">IOBuffer</span></code> instances for bulk memory, which increase by powers of 2.</p>
</div>
</div>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="RPC.en.html" title="RPC Refactor"
>next</a> |</li>
<li class="right" >
<a href="plugin-coordination.en.html" title="Plugin Coordination"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">SWOC Docs</a> »</li>
<li class="nav-item nav-item-1"><a href="ats-projects.en.html" >Traffic Server Projects</a> »</li>
</ul>
</div>
<div class="footer" role="contentinfo">
© Copyright 2017, [email protected].
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.6.6.
</div>
</body>
</html>