mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-01-01 09:51:22 -08:00
258 lines
No EOL
19 KiB
HTML
258 lines
No EOL
19 KiB
HTML
|
|
|
|
<!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>11. MVFF (Manual Variable First Fit) — Memory Pool System 1.111.0 documentation</title>
|
|
|
|
<link rel="stylesheet" href="../_static/mps.css" type="text/css" />
|
|
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
|
|
|
<script type="text/javascript">
|
|
var DOCUMENTATION_OPTIONS = {
|
|
URL_ROOT: '../',
|
|
VERSION: '1.111.0',
|
|
COLLAPSE_INDEX: false,
|
|
FILE_SUFFIX: '.html',
|
|
HAS_SOURCE: true
|
|
};
|
|
</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="copyright" title="Copyright" href="../copyright.html" />
|
|
<link rel="top" title="Memory Pool System 1.111.0 documentation" href="../index.html" />
|
|
<link rel="up" title="Pool reference" href="index.html" />
|
|
<link rel="next" title="12. MVT (Manual Variable Temporal)" href="mvt.html" />
|
|
<link rel="prev" title="10. MV (Manual Variable)" href="mv.html" />
|
|
</head>
|
|
<body>
|
|
<div class="related">
|
|
<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="mvt.html" title="12. MVT (Manual Variable Temporal)"
|
|
accesskey="N">next</a> |</li>
|
|
<li class="right" >
|
|
<a href="mv.html" title="10. MV (Manual Variable)"
|
|
accesskey="P">previous</a> |</li>
|
|
<li><a href="../index.html">Memory Pool System 1.111.0 documentation</a> »</li>
|
|
<li><a href="index.html" accesskey="U">Pool reference</a> »</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div class="document">
|
|
<div class="documentwrapper">
|
|
<div class="bodywrapper">
|
|
<div class="body">
|
|
|
|
<div class="section" id="mvff-manual-variable-first-fit">
|
|
<span id="pool-mvff"></span><span id="index-0"></span><h1>11. MVFF (Manual Variable First Fit)<a class="headerlink" href="#mvff-manual-variable-first-fit" title="Permalink to this headline">¶</a></h1>
|
|
<p><strong>MVFF</strong> <a class="reference internal" href="../glossary/m.html#term-manual-memory-management"><em class="xref std std-term">manually manages</em></a>
|
|
variable-sized, unformatted objects. It uses the <a class="reference internal" href="../glossary/f.html#term-first-fit"><em class="xref std std-term">first fit</em></a>
|
|
<a class="reference internal" href="../glossary/a.html#term-allocation-policy"><em class="xref std std-term">allocation policy</em></a> for blocks allocated via
|
|
<a class="reference internal" href="../topic/allocation.html#mps_alloc" title="mps_alloc"><tt class="xref c c-func docutils literal"><span class="pre">mps_alloc()</span></tt></a>.</p>
|
|
<p><a class="reference internal" href="../mmref/bib.html#johnstone97"><em>Johnstone (1997)</em></a> found that in his test cases:</p>
|
|
<blockquote>
|
|
<div>No version of <a class="reference internal" href="../glossary/b.html#term-best-fit"><em class="xref std std-term">best fit</em></a> had more than 5% actual
|
|
<a class="reference internal" href="../glossary/e.html#term-external-fragmentation"><em class="xref std std-term">fragmentation</em></a>. This is also true
|
|
for all versions of first fit that used an <a class="reference internal" href="../glossary/a.html#term-address-ordered-first-fit"><em class="xref std std-term">address-ordered
|
|
free list</em></a>, and the two versions of
|
|
first fit that used a <a class="reference internal" href="../glossary/f.html#term-fifo-ordered-first-fit"><em class="xref std std-term">FIFO free list</em></a>. This strongly suggests that the basic best-fit algorithm
|
|
and the first-fit algorithm with an address-ordered free list are
|
|
very robust algorithms.</div></blockquote>
|
|
<p>The MVFF pool class also supports buffered allocation (that is,
|
|
allocation via <a class="reference internal" href="../glossary/a.html#term-allocation-point"><em class="xref std std-term">allocation points</em></a>), and in this case, the
|
|
allocation policy is different: the buffers are filled according to
|
|
the <a class="reference internal" href="../glossary/w.html#term-worst-fit"><em class="xref std std-term">worst fit</em></a> policy, and allocation always proceeds upwards
|
|
from the base.</p>
|
|
<p>Buffered and unbuffered allocation can be used at the same time, but
|
|
the first allocation point must be created before any call to
|
|
<a class="reference internal" href="../topic/allocation.html#mps_alloc" title="mps_alloc"><tt class="xref c c-func docutils literal"><span class="pre">mps_alloc()</span></tt></a>.</p>
|
|
<p>It is usually not advisable to use buffered and unbuffered allocation
|
|
on the same pool, because the worst-fit policy of buffer filling will
|
|
grab all the large blocks, leading to severe fragmentation. If you
|
|
need both forms of allocation, use two separate pools.</p>
|
|
<p>Note that buffered allocation can’t allocate across segment boundaries
|
|
(see <a class="reference internal" href="../topic/allocation.html#topic-allocation-point-implementation"><em>Allocation point implementation</em></a> for the technical
|
|
reason). This can cause added external fragmentation if objects are
|
|
allocated that are a significant fraction of the segment size.</p>
|
|
<div class="admonition-note admonition">
|
|
<p class="first admonition-title">Note</p>
|
|
<p class="last">If you need to allocate large objects in an MVFF pool,
|
|
<a class="reference internal" href="../contact.html#contact"><em>contact us</em></a>.</p>
|
|
</div>
|
|
<div class="section" id="mvff-properties">
|
|
<span id="index-1"></span><h2>11.1. MVFF properties<a class="headerlink" href="#mvff-properties" title="Permalink to this headline">¶</a></h2>
|
|
<ul class="simple">
|
|
<li>Supports allocation via <a class="reference internal" href="../topic/allocation.html#mps_alloc" title="mps_alloc"><tt class="xref c c-func docutils literal"><span class="pre">mps_alloc()</span></tt></a>.</li>
|
|
<li>Supports allocation via <a class="reference internal" href="../glossary/a.html#term-allocation-point"><em class="xref std std-term">allocation points</em></a>. If an allocation
|
|
point is created in an MVFF pool, the call to
|
|
<a class="reference internal" href="../topic/allocation.html#mps_ap_create" title="mps_ap_create"><tt class="xref c c-func docutils literal"><span class="pre">mps_ap_create()</span></tt></a> takes no additional parameters.</li>
|
|
<li>Supports deallocation via <a class="reference internal" href="../topic/allocation.html#mps_free" title="mps_free"><tt class="xref c c-func docutils literal"><span class="pre">mps_free()</span></tt></a>.</li>
|
|
<li>Supports <a class="reference internal" href="../glossary/a.html#term-allocation-frame"><em class="xref std std-term">allocation frames</em></a> but does not use them to improve
|
|
the efficiency of stack-like allocation.</li>
|
|
<li>Supports <a class="reference internal" href="../glossary/s.html#term-segregated-allocation-cache"><em class="xref std std-term">segregated allocation caches</em></a>.</li>
|
|
<li>There are no garbage collections in this pool.</li>
|
|
<li>Blocks may not contain <a class="reference internal" href="../glossary/r.html#term-reference"><em class="xref std std-term">references</em></a> to blocks in automatically
|
|
managed pools (unless these are registered as <a class="reference internal" href="../glossary/r.html#term-root"><em class="xref std std-term">roots</em></a>).</li>
|
|
<li>Allocations may be variable in size.</li>
|
|
<li>The <a class="reference internal" href="../glossary/a.html#term-alignment"><em class="xref std std-term">alignment</em></a> of blocks is configurable, but may not be
|
|
smaller than the <a class="reference internal" href="../glossary/n.html#term-natural-alignment"><em class="xref std std-term">natural alignment</em></a> of the platform.</li>
|
|
<li>Blocks do not have <a class="reference internal" href="../glossary/d.html#term-dependent-object"><em class="xref std std-term">dependent objects</em></a>.</li>
|
|
<li>Blocks are not automatically <a class="reference internal" href="../glossary/r.html#term-reclaim"><em class="xref std std-term">reclaimed</em></a>.</li>
|
|
<li>Blocks are not <a class="reference internal" href="../glossary/s.html#term-scan"><em class="xref std std-term">scanned</em></a>.</li>
|
|
<li>Blocks are not protected by <a class="reference internal" href="../glossary/b.html#term-barrier-1"><em class="xref std std-term">barriers<sup>(1)</sup></em></a>.</li>
|
|
<li>Blocks do not <a class="reference internal" href="../glossary/m.html#term-moving-garbage-collector"><em class="xref std std-term">move</em></a>.</li>
|
|
<li>Blocks may not be registered for <a class="reference internal" href="../glossary/f.html#term-finalization"><em class="xref std std-term">finalization</em></a>.</li>
|
|
<li>Blocks must not belong to an <a class="reference internal" href="../glossary/o.html#term-object-format"><em class="xref std std-term">object format</em></a>.</li>
|
|
</ul>
|
|
</div>
|
|
<div class="section" id="mvff-interface">
|
|
<span id="index-2"></span><h2>11.2. MVFF interface<a class="headerlink" href="#mvff-interface" title="Permalink to this headline">¶</a></h2>
|
|
<div class="highlight-c"><div class="highlight"><pre><span class="cp">#include "mpscmvff.h"</span>
|
|
</pre></div>
|
|
</div>
|
|
<dl class="function">
|
|
<dt id="mps_class_mvff">
|
|
<a class="reference internal" href="../topic/pool.html#mps_class_t" title="mps_class_t">mps_class_t</a> <tt class="descname">mps_class_mvff</tt><big>(</big>void<big>)</big><a class="headerlink" href="#mps_class_mvff" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>Return the <a class="reference internal" href="../glossary/p.html#term-pool-class"><em class="xref std std-term">pool class</em></a> for an MVFF (Manual Variable First
|
|
Fit) <a class="reference internal" href="../glossary/p.html#term-pool"><em class="xref std std-term">pool</em></a>.</p>
|
|
<p>When creating an MVFF pool, <a class="reference internal" href="../topic/pool.html#mps_pool_create" title="mps_pool_create"><tt class="xref c c-func docutils literal"><span class="pre">mps_pool_create()</span></tt></a> takes six
|
|
extra arguments:</p>
|
|
<div class="highlight-c"><div class="highlight"><pre><span class="n">mps_res_t</span> <span class="n">mps_pool_create</span><span class="p">(</span><span class="n">mps_pool_t</span> <span class="o">*</span><span class="n">pool_o</span><span class="p">,</span> <span class="n">mps_arena_t</span> <span class="n">arena</span><span class="p">,</span>
|
|
<span class="n">mps_class_t</span> <span class="n">mps_class_mvff</span><span class="p">(),</span>
|
|
<span class="n">mps_size_t</span> <span class="n">extend_size</span><span class="p">,</span>
|
|
<span class="n">mps_size_t</span> <span class="n">average_size</span><span class="p">,</span>
|
|
<span class="n">mps_align_t</span> <span class="n">alignment</span><span class="p">,</span>
|
|
<span class="n">mps_bool_t</span> <span class="n">slot_high</span><span class="p">,</span>
|
|
<span class="n">mps_bool_t</span> <span class="n">arena_high</span><span class="p">,</span>
|
|
<span class="n">mps_bool_t</span> <span class="n">first_fit</span><span class="p">)</span>
|
|
</pre></div>
|
|
</div>
|
|
<p><tt class="docutils literal"><span class="pre">extend_size</span></tt> is the <a class="reference internal" href="../glossary/s.html#term-size"><em class="xref std std-term">size</em></a> of segment that the pool will
|
|
request from the <a class="reference internal" href="../glossary/a.html#term-arena"><em class="xref std std-term">arena</em></a>.</p>
|
|
<p><tt class="docutils literal"><span class="pre">average_size</span></tt> is the predicted average size of blocks that will
|
|
be allocated from the pool.</p>
|
|
<p><tt class="docutils literal"><span class="pre">alignment</span></tt> is the <a class="reference internal" href="../glossary/a.html#term-alignment"><em class="xref std std-term">alignment</em></a> of addresses for allocation
|
|
(and freeing) in the pool. If an unaligned size is passed to
|
|
<a class="reference internal" href="../topic/allocation.html#mps_alloc" title="mps_alloc"><tt class="xref c c-func docutils literal"><span class="pre">mps_alloc()</span></tt></a> or <a class="reference internal" href="../topic/allocation.html#mps_free" title="mps_free"><tt class="xref c c-func docutils literal"><span class="pre">mps_free()</span></tt></a>, it will be rounded up
|
|
to the pool’s alignment. The minimum alignment supported by pools
|
|
of this class is <tt class="docutils literal"><span class="pre">sizeof(void</span> <span class="pre">*)</span></tt>.</p>
|
|
<p><tt class="docutils literal"><span class="pre">slot_high</span></tt> is undocumented. It must have the same value as
|
|
<tt class="docutils literal"><span class="pre">arena_high</span></tt>.</p>
|
|
<p>If <tt class="docutils literal"><span class="pre">arena_high</span></tt> is true, new segments for buffered allocation
|
|
are acquired at high addresses; if false, at low addresses.</p>
|
|
<p><tt class="docutils literal"><span class="pre">first_fit</span></tt> is undocumented and must be set to true.</p>
|
|
</dd></dl>
|
|
|
|
<dl class="function">
|
|
<dt id="mps_class_mvff_debug">
|
|
<a class="reference internal" href="../topic/pool.html#mps_class_t" title="mps_class_t">mps_class_t</a> <tt class="descname">mps_class_mvff_debug</tt><big>(</big>void<big>)</big><a class="headerlink" href="#mps_class_mvff_debug" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>A <a class="reference internal" href="../topic/debugging.html#topic-debugging"><em>debugging</em></a> version of the MVFF pool
|
|
class.</p>
|
|
<p>When creating a debugging MVFF pool, <a class="reference internal" href="../topic/pool.html#mps_pool_create" title="mps_pool_create"><tt class="xref c c-func docutils literal"><span class="pre">mps_pool_create()</span></tt></a>
|
|
takes seven extra arguments:</p>
|
|
<div class="highlight-c"><div class="highlight"><pre><span class="n">mps_res_t</span> <span class="n">mps_pool_create</span><span class="p">(</span><span class="n">mps_pool_t</span> <span class="o">*</span><span class="n">pool_o</span><span class="p">,</span> <span class="n">mps_arena_t</span> <span class="n">arena</span><span class="p">,</span>
|
|
<span class="n">mps_class_t</span> <span class="n">mps_class_mvff_debug</span><span class="p">(),</span>
|
|
<span class="n">mps_debug_option_s</span> <span class="n">debug_option</span><span class="p">,</span>
|
|
<span class="n">mps_size_t</span> <span class="n">extend_size</span><span class="p">,</span>
|
|
<span class="n">mps_size_t</span> <span class="n">average_size</span><span class="p">,</span>
|
|
<span class="n">mps_align_t</span> <span class="n">alignment</span><span class="p">,</span>
|
|
<span class="n">mps_bool_t</span> <span class="n">slot_high</span><span class="p">,</span>
|
|
<span class="n">mps_bool_t</span> <span class="n">arena_high</span><span class="p">,</span>
|
|
<span class="n">mps_bool_t</span> <span class="n">first_fit</span><span class="p">)</span>
|
|
</pre></div>
|
|
</div>
|
|
<p><tt class="docutils literal"><span class="pre">debug_option</span></tt> specifies the debugging options. See
|
|
<tt class="xref c c-type docutils literal"><span class="pre">mps_debug_option_s</span></tt>.</p>
|
|
<p>The other arguments are the same as for <a class="reference internal" href="#mps_class_mvff" title="mps_class_mvff"><tt class="xref c c-func docutils literal"><span class="pre">mps_class_mvff()</span></tt></a>.</p>
|
|
</dd></dl>
|
|
|
|
</div>
|
|
<div class="section" id="mvff-introspection">
|
|
<span id="index-3"></span><h2>11.3. MVFF introspection<a class="headerlink" href="#mvff-introspection" title="Permalink to this headline">¶</a></h2>
|
|
<div class="highlight-c"><div class="highlight"><pre><span class="cp">#include "mpscmvff.h"</span>
|
|
</pre></div>
|
|
</div>
|
|
<dl class="function">
|
|
<dt id="mps_mvff_free_size">
|
|
size_t <tt class="descname">mps_mvff_free_size</tt><big>(</big><a class="reference internal" href="../topic/pool.html#mps_pool_t" title="mps_pool_t">mps_pool_t</a><em> pool</em><big>)</big><a class="headerlink" href="#mps_mvff_free_size" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>Return the total amount of free space in an MVFF pool.</p>
|
|
<p><tt class="docutils literal"><span class="pre">pool</span></tt> is the MVFF pool.</p>
|
|
<p>Returns the total free space in the pool, in <a class="reference internal" href="../glossary/b.html#term-byte-1"><em class="xref std std-term">bytes<sup>(1)</sup></em></a>.</p>
|
|
</dd></dl>
|
|
|
|
<dl class="function">
|
|
<dt id="mps_mvff_size">
|
|
size_t <tt class="descname">mps_mvff_size</tt><big>(</big><a class="reference internal" href="../topic/pool.html#mps_pool_t" title="mps_pool_t">mps_pool_t</a><em> pool</em><big>)</big><a class="headerlink" href="#mps_mvff_size" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>Return the total size of an MVFF pool.</p>
|
|
<p><tt class="docutils literal"><span class="pre">pool</span></tt> is the MVFF pool.</p>
|
|
<p>Returns the total size of the pool, in <a class="reference internal" href="../glossary/b.html#term-byte-1"><em class="xref std std-term">bytes<sup>(1)</sup></em></a>. This
|
|
is the sum of allocated space and free space.</p>
|
|
</dd></dl>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="sphinxsidebar">
|
|
<div class="sphinxsidebarwrapper">
|
|
<p class="logo"><a href="../index.html">
|
|
<img class="logo" src="../_static/logo.png" alt="Logo"/>
|
|
</a></p>
|
|
<h3><a href="../index.html">Table Of Contents</a></h3>
|
|
<ul>
|
|
<li><a class="reference internal" href="#">11. MVFF (Manual Variable First Fit)</a><ul>
|
|
<li><a class="reference internal" href="#mvff-properties">11.1. MVFF properties</a></li>
|
|
<li><a class="reference internal" href="#mvff-interface">11.2. MVFF interface</a></li>
|
|
<li><a class="reference internal" href="#mvff-introspection">11.3. MVFF introspection</a></li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
|
|
<h4>Previous topic</h4>
|
|
<p class="topless"><a href="mv.html"
|
|
title="previous chapter">10. MV (Manual Variable)</a></p>
|
|
<h4>Next topic</h4>
|
|
<p class="topless"><a href="mvt.html"
|
|
title="next chapter">12. MVT (Manual Variable Temporal)</a></p><h4>Contact us</h4>
|
|
|
|
<p class="topless"><a href="mailto:mps-questions@ravenbrook.com">mps-questions@ravenbrook.com</a></p>
|
|
</div>
|
|
</div>
|
|
<div class="clearer"></div>
|
|
</div>
|
|
<div class="related">
|
|
<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="mvt.html" title="12. MVT (Manual Variable Temporal)"
|
|
>next</a> |</li>
|
|
<li class="right" >
|
|
<a href="mv.html" title="10. MV (Manual Variable)"
|
|
>previous</a> |</li>
|
|
<li><a href="../index.html">Memory Pool System 1.111.0 documentation</a> »</li>
|
|
<li><a href="index.html" >Pool reference</a> »</li>
|
|
</ul>
|
|
</div>
|
|
<div class="footer">
|
|
© <a href="../copyright.html">Copyright</a> 2012, Ravenbrook Limited.
|
|
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
|
|
</div>
|
|
</body>
|
|
</html> |