blob: a96d546ee169ff4d2573f4e5f7737ca497e430d7 [file] [log] [blame]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Memory Pools &mdash; Apache Mynewt latest documentation</title>
<link rel="shortcut icon" href="../../../_static/mynewt-logo-only-newt32x32.png"/>
<link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/css/sphinx_theme.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/css/bootstrap-3.0.3.min.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/css/v2.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/css/custom.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/css/restructuredtext.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/css/overrides.css" type="text/css" />
<link rel="index" title="Index"
href="../../../genindex.html"/>
<link rel="search" title="Search" href="../../../search.html"/>
<link rel="top" title="Apache Mynewt latest documentation" href="../../../index.html"/>
<link rel="up" title="Apache Mynewt Operating System Kernel" href="../mynewt_os.html"/>
<link rel="next" title="Mbufs" href="../mbuf/mbuf.html"/>
<link rel="prev" title="Heap" href="../heap/heap.html"/>
<script src="../../../_static/js/modernizr.min.js"></script>
<script>
(function(i, s, o, g, r, a, m) {
i["GoogleAnalyticsObject"] = r;
(i[r] =
i[r] ||
function() {
(i[r].q = i[r].q || []).push(arguments);
}),
(i[r].l = 1 * new Date());
(a = s.createElement(o)), (m = s.getElementsByTagName(o)[0]);
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m);
})(window, document, "script", "//www.google-analytics.com/analytics.js", "ga");
ga("create", "UA-72162311-1", "auto");
ga("send", "pageview");
</script>
</head>
<body class="not-front page-documentation" role="document" >
<div id="wrapper">
<div class="container">
<div id="banner" class="row v2-main-banner">
<a class="logo-cell" href="/">
<img class="logo" src="../../../_static/img/logo.png">
</a>
<div class="tagline-cell">
<h4 class="tagline">An OS to build, deploy and securely manage billions of devices</h4>
</div>
<div class="news-cell">
<div class="well">
<h4>Latest News:</h4> <a href="/download">Apache Mynewt 1.12.0, Apache NimBLE 1.7.0 </a> released April 4, 2024)
</div>
</div>
</div>
</div>
<header>
<nav id="navbar" class="navbar navbar-inverse" role="navigation">
<div class="container">
<!-- Collapsed navigation -->
<div class="navbar-header">
<!-- Expander button -->
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<!-- Expanded navigation -->
<div class="navbar-collapse collapse">
<!-- Main navigation -->
<ul class="nav navbar-nav navbar-right">
<li>
<a href="/"><i class="fa fa-home" style="font-size: larger;"></i></a>
</li>
<li class="important">
<a href="/quick-start/">Quick Start</a>
</li>
<li>
<a href="/about/">About</a>
</li>
<li>
<a href="/talks/">Talks</a>
</li>
<li class="active">
<a href="/documentation/">Documentation</a>
</li>
<li>
<a href="/download/">Download</a>
</li>
<li>
<a href="/community/">Community</a>
</li>
<li>
<a href="/events/">Events</a>
</li>
</ul>
<!-- Search, Navigation and Repo links -->
<ul class="nav navbar-nav navbar-right">
</ul>
</div>
</div>
</nav>
</header>
<!-- STARTS MAIN CONTENT -->
<div id="main-content">
<div id="breadcrumb">
<div class="container">
<a href="/documentation/">Docs</a> /
<a href="../../os_user_guide.html">OS User Guide</a> /
<a href="../mynewt_os.html">Apache Mynewt Operating System Kernel</a> /
Memory Pools
<div class="sourcelink">
<a href="https://github.com/apache/mynewt-core/edit/master/docs/os/core_os/memory_pool/memory_pool.rst" class="icon icon-github"
rel="nofollow"> Edit on GitHub</a>
</div>
</div>
</div>
<!-- STARTS CONTAINER -->
<div class="container">
<!-- STARTS .content -->
<div id="content" class="row">
<!-- STARTS .container-sidebar -->
<div class="container-sidebar col-xs-12 col-sm-3">
<div id="docSidebar" class="sticky-container">
<div role="search" class="sphinx-search">
<form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
<input type="text" name="q" placeholder="Search documentation" class="search-documentation" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<!-- Note: only works when deployed -->
<select class="form-control" onchange="if (this.value) window.location.href=this.value">
<option value="/latest" selected>
Version: latest
</option>
<option value="/v1_12_0" >
Version: 1.12.0
</option>
<option value="/v1_11_0" >
Version: 1.11.0
</option>
<option value="/v1_10_0" >
Version: 1.10.0
</option>
<option value="/v1_9_0" >
Version: 1.9.0
</option>
<option value="/v1_8_0" >
Version: 1.8.0
</option>
<option value="/v1_7_0" >
Version: 1.7.0
</option>
<option value="/v1_6_0" >
Version: 1.6.0
</option>
<option value="/v1_5_0" >
Version: 1.5.0
</option>
<option value="/v1_4_0" selected="selected" >
Version: 1.4.0
</option>
<option value="/v1_3_0/os/introduction" >
Version: 1.3.0
</option>
<option value="/v1_2_0/os/introduction" >
Version: 1.2.0
</option>
<option value="/v1_1_0/os/introduction" >
Version: 1.1.0
</option>
<option value="/v1_0_0/os/introduction" >
Version: 1.0.0
</option>
<option value="/v0_9_0/os/introduction" >
Version: 0.9.0
</option>
</select>
<div class="region region-sidebar">
<div class="docs-menu">
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../../../index.html">Introduction</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../get_started/index.html">Setup &amp; Get Started</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../concepts.html">Concepts</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../tutorials/tutorials.html">Tutorials</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../external_links.html">Third-party Resources</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../../os_user_guide.html">OS User Guide</a><ul class="current">
<li class="toctree-l2 current"><a class="reference internal" href="../mynewt_os.html">Kernel</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="../context_switch/context_switch.html">Scheduler</a></li>
<li class="toctree-l3"><a class="reference internal" href="../task/task.html">Task</a></li>
<li class="toctree-l3"><a class="reference internal" href="../mutex/mutex.html">Mutex</a></li>
<li class="toctree-l3"><a class="reference internal" href="../semaphore/semaphore.html">Semaphore</a></li>
<li class="toctree-l3"><a class="reference internal" href="../event_queue/event_queue.html">Event Queues</a></li>
<li class="toctree-l3"><a class="reference internal" href="../callout/callout.html">Callout</a></li>
<li class="toctree-l3"><a class="reference internal" href="../heap/heap.html">Heap</a></li>
<li class="toctree-l3 current"><a class="current reference internal" href="#">Memory Pools</a></li>
<li class="toctree-l3"><a class="reference internal" href="../mbuf/mbuf.html">Mbufs</a></li>
<li class="toctree-l3"><a class="reference internal" href="../cputime/os_cputime.html">CPU Time</a></li>
<li class="toctree-l3"><a class="reference internal" href="../time/os_time.html">OS Time</a></li>
<li class="toctree-l3"><a class="reference internal" href="../sanity/sanity.html">Sanity</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../modules/system_modules.html">System</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../modules/hal/hal.html">Hardware Abstraction</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../modules/bootloader/bootloader.html">Secure Bootloader</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../modules/split/split.html">Split Images</a></li>
<li class="toctree-l2"><a class="reference internal" href="../porting/port_os.html">Porting Guide</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../modules/sysinitconfig/sysinitconfig.html">Compile-Time Configuration</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../modules/console/console.html">Console</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../modules/shell/shell.html">Shell</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../modules/testutil/testutil.html">Test Utilities</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../modules/json/json.html">JSON</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../modules/stats/stats.html">Statistics</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../modules/logs/logs.html">Logs</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../../network/index.html">BLE User Guide</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../newt/index.html">Newt Tool Guide</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../newtmgr/index.html">Newt Manager Guide</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../mynewt_faq/index.html">Mynewt FAQ</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../misc/index.html">Appendix</a></li>
</ul>
</div>
</div>
</div>
<!-- ENDS STICKY CONTAINER -->
</div>
<!-- ENDS .container-sidebar -->
<div class="col-xs-12 col-sm-9">
<div class="alert alert-warning">
<p>
Version 1.4.0 is not the most recent version of the
Apache Mynewt documentation. Click <a href="/latest">here</a> to
read the latest version.
</p>
</div>
<div class="">
<div class="rst-content">
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="memory-pools">
<h1>Memory Pools<a class="headerlink" href="#memory-pools" title="Permalink to this headline"></a></h1>
<p>A memory pool is a collection of fixed sized elements called memory
blocks. Generally, memory pools are used when the developer wants to
allocate a certain amount of memory to a given feature. Unlike the heap,
where a code module is at the mercy of other code modules to insure
there is sufficient memory, memory pools can insure sufficient memory
allocation.</p>
<div class="section" id="description">
<h2>Description<a class="headerlink" href="#description" title="Permalink to this headline"></a></h2>
<p>In order to create a memory pool the developer needs to do a few things.
The first task is to define the memory pool itself. This is a data
structure which contains information about the pool itself (i.e. number
of blocks, size of the blocks, etc).</p>
<div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="k">struct</span><span class="w"> </span><span class="nc">os_mempool</span><span class="w"> </span><span class="n">my_pool</span><span class="p">;</span>
</pre></div>
</div>
<p>The next order of business is to allocate the memory used by the memory
pool. This memory can either be statically allocated (i.e. a global
variable) or dynamically allocated (i.e. from the heap). When
determining the amount of memory required for the memory pool, simply
multiplying the number of blocks by the size of each block is not
sufficient as the OS may have alignment requirements. The alignment size
definition is named <code class="xref c c-macro docutils literal notranslate"><span class="pre">OS_ALIGNMENT</span></code> and can be found in os_arch.h as
it is architecture specific. The memory block alignment is usually for
efficiency but may be due to other reasons. Generally, blocks are
aligned on 32-bit boundaries. Note that memory blocks must also be of
sufficient size to hold a list pointer as this is needed to chain memory
blocks on the free list.</p>
<p>In order to simplify this for the user two macros have been provided:
c:macro:<cite>OS_MEMPOOL_BYTES(n, blksize)</cite> and <code class="xref c c-macro docutils literal notranslate"><span class="pre">OS_MEMPOOL_SIZE(n,</span> <span class="pre">blksize)</span></code>.
The first macro returns the number of bytes needed for the memory pool
while the second returns the number of <code class="xref c c-type docutils literal notranslate"><span class="pre">os_membuf_t`</span></code> elements required
by the memory pool. The <a class="reference internal" href="#c.os_membuf_t" title="os_membuf_t"><code class="xref c c-type docutils literal notranslate"><span class="pre">os_membuf_t</span></code></a> type is used to guarantee that
the memory buffer used by the memory pool is aligned on the correct
boundary.</p>
<p>Here are some examples. Note that if a custom malloc implementation is
used it must guarantee that the memory buffer used by the pool is
allocated on the correct boundary (i.e. <code class="xref c c-macro docutils literal notranslate"><span class="pre">OS_ALIGNMENT</span></code>).</p>
<div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">my_memory_buffer</span><span class="p">;</span>
<span class="n">my_memory_buffer</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">malloc</span><span class="p">(</span><span class="n">OS_MEMPOOL_BYTES</span><span class="p">(</span><span class="n">NUM_BLOCKS</span><span class="p">,</span><span class="w"> </span><span class="n">BLOCK_SIZE</span><span class="p">));</span>
</pre></div>
</div>
<div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="n">os_membuf_t</span><span class="w"> </span><span class="n">my_memory_buffer</span><span class="p">[</span><span class="n">OS_MEMPOOL_SIZE</span><span class="p">(</span><span class="n">NUM_BLOCKS</span><span class="p">,</span><span class="w"> </span><span class="n">BLOCK_SIZE</span><span class="p">)];</span>
</pre></div>
</div>
<p>Now that the memory pool has been defined as well as the memory
required for the memory blocks which make up the pool the user needs to
initialize the memory pool by calling <code class="xref c c-func docutils literal notranslate"><span class="pre">os_mempool_init`()</span></code>.</p>
<div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="n">os_mempool_init</span><span class="p">(</span><span class="o">&amp;</span><span class="n">my_pool</span><span class="p">,</span><span class="w"> </span><span class="n">NUM_BLOCKS</span><span class="p">,</span><span class="w"> </span><span class="n">BLOCK_SIZE</span><span class="p">,</span><span class="w"> </span><span class="n">my_memory_buffer</span><span class="p">,</span>
<span class="w"> </span><span class="s">&quot;MyPool&quot;</span><span class="p">);</span>
</pre></div>
</div>
<p>Once the memory pool has been initialized the developer can allocate
memory blocks from the pool by calling <a class="reference internal" href="#c.os_memblock_get" title="os_memblock_get"><code class="xref c c-func docutils literal notranslate"><span class="pre">os_memblock_get()</span></code></a>. When the
memory block is no longer needed the memory can be freed by calling
<a class="reference internal" href="#c.os_memblock_put" title="os_memblock_put"><code class="xref c c-func docutils literal notranslate"><span class="pre">os_memblock_put()</span></code></a>.</p>
</div>
<div class="section" id="api">
<h2>API<a class="headerlink" href="#api" title="Permalink to this headline"></a></h2>
<dl class="c type">
<dt id="c.os_mempool_put_fn">
<span class="target" id="group___o_s_mempool_1gac78e7cbbf707f8e5399843aae28b2d9d"></span><em class="property"><span class="pre">typedef</span> </em><span class="pre">os_error_t</span> <code class="sig-name descname"><span class="pre">os_mempool_put_fn</span></code><span class="sig-paren">(</span><em class="property"><span class="pre">struct</span></em> <a class="reference internal" href="#c.os_mempool_ext" title="os_mempool_ext"><span class="pre">os_mempool_ext</span></a> <span class="pre">*</span><em><span class="pre">ome</span></em>, <span class="pre">void</span> <span class="pre">*</span><em><span class="pre">data</span></em>, <span class="pre">void</span> <span class="pre">*</span><em><span class="pre">arg</span></em><span class="sig-paren">)</span><a class="headerlink" href="#c.os_mempool_put_fn" title="Permalink to this definition"></a><br /></dt>
<dd><p>Block put callback function. </p>
<p>If configured, this callback gets executed whenever a block is freed to the corresponding extended mempool. Note: The <a class="reference internal" href="#group___o_s_mempool_1gaf6178bdc593729880d9d2bb7e23e11b0"><span class="std std-ref">os_memblock_put()</span></a> function calls this callback instead of freeing the block itself. Therefore, it is the callback’s responsibility to free the block via a call to <a class="reference internal" href="#group___o_s_mempool_1gacbcaf7e356d49c4f84612e5a0d882596"><span class="std std-ref">os_memblock_put_from_cb()</span></a>.</p>
<p><dl class="simple">
<dt><strong>Return</strong></dt><dd><p>Indicates whether the block was successfully freed. A non-zero value should only be returned if the block was not successfully released back to its pool. </p>
</dd>
<dt><strong>Parameters</strong></dt><dd><ul class="breatheparameterlist simple">
<li><p><code class="docutils literal notranslate"><span class="pre">ome</span></code>: The extended mempool that a block is being freed back to. </p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">data</span></code>: The block being freed. </p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">arg</span></code>: Optional argument configured along with the callback.</p></li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="c type">
<dt id="c.os_membuf_t">
<span class="target" id="group___o_s_mempool_1ga0615acb24ae94e5a5a337b424c70fd6a"></span><em class="property"><span class="pre">typedef</span> </em><span class="pre">uint32_t</span> <code class="sig-name descname"><span class="pre">os_membuf_t</span></code><a class="headerlink" href="#c.os_membuf_t" title="Permalink to this definition"></a><br /></dt>
<dd></dd></dl>
<dl class="c function">
<dt id="c.os_mempool_info_get_next">
<span class="target" id="group___o_s_mempool_1gae80195d443ae18bf7298eabcfe550b22"></span><em class="property"><span class="pre">struct</span></em> <a class="reference internal" href="#c.os_mempool" title="os_mempool"><span class="pre">os_mempool</span></a> <span class="pre">*</span><code class="sig-name descname"><span class="pre">os_mempool_info_get_next</span></code><span class="sig-paren">(</span><em class="property"><span class="pre">struct</span></em> <a class="reference internal" href="#c.os_mempool" title="os_mempool"><span class="pre">os_mempool</span></a><span class="pre">*</span>, <em class="property"><span class="pre">struct</span></em> <a class="reference internal" href="#c.os_mempool_info" title="os_mempool_info"><span class="pre">os_mempool_info</span></a><span class="pre">*</span><span class="sig-paren">)</span><a class="headerlink" href="#c.os_mempool_info_get_next" title="Permalink to this definition"></a><br /></dt>
<dd><p>Get information about the next system memory pool. </p>
<p><dl class="simple">
<dt><strong>Return</strong></dt><dd><p>The next memory pool in the list to get information about, or NULL when at the last memory pool. </p>
</dd>
<dt><strong>Parameters</strong></dt><dd><ul class="breatheparameterlist simple">
<li><p><code class="docutils literal notranslate"><span class="pre">mempool</span></code>: The current memory pool, or NULL if starting iteration. </p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">info</span></code>: A pointer to the structure to return memory pool information into.</p></li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="c function">
<dt id="c.os_mempool_init">
<span class="target" id="group___o_s_mempool_1gadcf2c1941c73b2ad97e05a1d36e8234d"></span><span class="pre">os_error_t</span> <code class="sig-name descname"><span class="pre">os_mempool_init</span></code><span class="sig-paren">(</span><em class="property"><span class="pre">struct</span></em> <a class="reference internal" href="#c.os_mempool" title="os_mempool"><span class="pre">os_mempool</span></a> <span class="pre">*</span><em><span class="pre">mp</span></em>, <span class="pre">uint16_t</span> <em><span class="pre">blocks</span></em>, <span class="pre">uint32_t</span> <em><span class="pre">block_size</span></em>, <span class="pre">void</span> <span class="pre">*</span><em><span class="pre">membuf</span></em>, <span class="pre">char</span> <span class="pre">*</span><em><span class="pre">name</span></em><span class="sig-paren">)</span><a class="headerlink" href="#c.os_mempool_init" title="Permalink to this definition"></a><br /></dt>
<dd><p>Initialize a memory pool. </p>
<p><dl class="simple">
<dt><strong>Return</strong></dt><dd><p>os_error_t </p>
</dd>
<dt><strong>Parameters</strong></dt><dd><ul class="breatheparameterlist simple">
<li><p><code class="docutils literal notranslate"><span class="pre">mp</span></code>: Pointer to a pointer to a mempool </p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">blocks</span></code>: The number of blocks in the pool </p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">blocks_size</span></code>: The size of the block, in bytes. </p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">membuf</span></code>: Pointer to memory to contain blocks. </p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">name</span></code>: Name of the pool.</p></li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="c function">
<dt id="c.os_mempool_ext_init">
<span class="target" id="group___o_s_mempool_1gacb506516fd3695bf9649aef5ac384d53"></span><span class="pre">os_error_t</span> <code class="sig-name descname"><span class="pre">os_mempool_ext_init</span></code><span class="sig-paren">(</span><em class="property"><span class="pre">struct</span></em> <a class="reference internal" href="#c.os_mempool_ext" title="os_mempool_ext"><span class="pre">os_mempool_ext</span></a> <span class="pre">*</span><em><span class="pre">mpe</span></em>, <span class="pre">uint16_t</span> <em><span class="pre">blocks</span></em>, <span class="pre">uint32_t</span> <em><span class="pre">block_size</span></em>, <span class="pre">void</span> <span class="pre">*</span><em><span class="pre">membuf</span></em>, <span class="pre">char</span> <span class="pre">*</span><em><span class="pre">name</span></em><span class="sig-paren">)</span><a class="headerlink" href="#c.os_mempool_ext_init" title="Permalink to this definition"></a><br /></dt>
<dd><p>Initializes an extended memory pool. </p>
<p>Extended attributes (e.g., callbacks) are not specified when this function is called; they are assigned manually after initialization.</p>
<p><dl class="simple">
<dt><strong>Return</strong></dt><dd><p>os_error_t </p>
</dd>
<dt><strong>Parameters</strong></dt><dd><ul class="breatheparameterlist simple">
<li><p><code class="docutils literal notranslate"><span class="pre">mpe</span></code>: The extended memory pool to initialize. </p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">blocks</span></code>: The number of blocks in the pool. </p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">block_size</span></code>: The size of each block, in bytes. </p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">membuf</span></code>: Pointer to memory to contain blocks. </p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">name</span></code>: Name of the pool.</p></li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="c function">
<dt id="c.os_mempool_clear">
<span class="target" id="group___o_s_mempool_1gabae129c70f5fcd1d00189ffd43a29cd3"></span><span class="pre">os_error_t</span> <code class="sig-name descname"><span class="pre">os_mempool_clear</span></code><span class="sig-paren">(</span><em class="property"><span class="pre">struct</span></em> <a class="reference internal" href="#c.os_mempool" title="os_mempool"><span class="pre">os_mempool</span></a> <span class="pre">*</span><em><span class="pre">mp</span></em><span class="sig-paren">)</span><a class="headerlink" href="#c.os_mempool_clear" title="Permalink to this definition"></a><br /></dt>
<dd><p>Clears a memory pool. </p>
<p><dl class="simple">
<dt><strong>Return</strong></dt><dd><p>os_error_t </p>
</dd>
<dt><strong>Parameters</strong></dt><dd><ul class="breatheparameterlist simple">
<li><p><code class="docutils literal notranslate"><span class="pre">mp</span></code>: The mempool to clear.</p></li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="c function">
<dt id="c.os_mempool_is_sane">
<span class="target" id="group___o_s_mempool_1ga94f119d4163b6ad4b5c41f11c0628e5d"></span><span class="pre">bool</span> <code class="sig-name descname"><span class="pre">os_mempool_is_sane</span></code><span class="sig-paren">(</span><em class="property"><span class="pre">const</span></em> <em class="property"><span class="pre">struct</span></em> <a class="reference internal" href="#c.os_mempool" title="os_mempool"><span class="pre">os_mempool</span></a> <span class="pre">*</span><em><span class="pre">mp</span></em><span class="sig-paren">)</span><a class="headerlink" href="#c.os_mempool_is_sane" title="Permalink to this definition"></a><br /></dt>
<dd><p>Performs an integrity check of the specified mempool. </p>
<p>This function attempts to detect memory corruption in the specified memory pool.</p>
<p><dl class="simple">
<dt><strong>Return</strong></dt><dd><p>true if the memory pool passes the integrity check; false if the memory pool is corrupt. </p>
</dd>
<dt><strong>Parameters</strong></dt><dd><ul class="breatheparameterlist simple">
<li><p><code class="docutils literal notranslate"><span class="pre">mp</span></code>: The mempool to check.</p></li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="c function">
<dt id="c.os_memblock_from">
<span class="target" id="group___o_s_mempool_1gaeda86bc0aa05a01cffe5934bede45041"></span><span class="pre">int</span> <code class="sig-name descname"><span class="pre">os_memblock_from</span></code><span class="sig-paren">(</span><em class="property"><span class="pre">const</span></em> <em class="property"><span class="pre">struct</span></em> <a class="reference internal" href="#c.os_mempool" title="os_mempool"><span class="pre">os_mempool</span></a> <span class="pre">*</span><em><span class="pre">mp</span></em>, <em class="property"><span class="pre">const</span></em> <span class="pre">void</span> <span class="pre">*</span><em><span class="pre">block_addr</span></em><span class="sig-paren">)</span><a class="headerlink" href="#c.os_memblock_from" title="Permalink to this definition"></a><br /></dt>
<dd><p>Checks if a memory block was allocated from the specified mempool. </p>
<p><dl class="simple">
<dt><strong>Return</strong></dt><dd><p>0 if the block does not belong to the mempool; 1 if the block does belong to the mempool. </p>
</dd>
<dt><strong>Parameters</strong></dt><dd><ul class="breatheparameterlist simple">
<li><p><code class="docutils literal notranslate"><span class="pre">mp</span></code>: The mempool to check as parent. </p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">block_addr</span></code>: The memory block to check as child.</p></li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="c function">
<dt id="c.os_memblock_get">
<span class="target" id="group___o_s_mempool_1ga5b08e22ecfe88e4563c9577354410676"></span><span class="pre">void</span> <span class="pre">*</span><code class="sig-name descname"><span class="pre">os_memblock_get</span></code><span class="sig-paren">(</span><em class="property"><span class="pre">struct</span></em> <a class="reference internal" href="#c.os_mempool" title="os_mempool"><span class="pre">os_mempool</span></a> <span class="pre">*</span><em><span class="pre">mp</span></em><span class="sig-paren">)</span><a class="headerlink" href="#c.os_memblock_get" title="Permalink to this definition"></a><br /></dt>
<dd><p>Get a memory block from a memory pool. </p>
<p><dl class="simple">
<dt><strong>Return</strong></dt><dd><p>void* Pointer to block if available; NULL otherwise </p>
</dd>
<dt><strong>Parameters</strong></dt><dd><ul class="breatheparameterlist simple">
<li><p><code class="docutils literal notranslate"><span class="pre">mp</span></code>: Pointer to the memory pool</p></li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="c function">
<dt id="c.os_memblock_put_from_cb">
<span class="target" id="group___o_s_mempool_1gacbcaf7e356d49c4f84612e5a0d882596"></span><span class="pre">os_error_t</span> <code class="sig-name descname"><span class="pre">os_memblock_put_from_cb</span></code><span class="sig-paren">(</span><em class="property"><span class="pre">struct</span></em> <a class="reference internal" href="#c.os_mempool" title="os_mempool"><span class="pre">os_mempool</span></a> <span class="pre">*</span><em><span class="pre">mp</span></em>, <span class="pre">void</span> <span class="pre">*</span><em><span class="pre">block_addr</span></em><span class="sig-paren">)</span><a class="headerlink" href="#c.os_memblock_put_from_cb" title="Permalink to this definition"></a><br /></dt>
<dd><p>Puts the memory block back into the pool, ignoring the put callback, if any. </p>
<p>This function should only be called from a put callback to free a block without causing infinite recursion.</p>
<p><dl class="simple">
<dt><strong>Return</strong></dt><dd><p>os_error_t </p>
</dd>
<dt><strong>Parameters</strong></dt><dd><ul class="breatheparameterlist simple">
<li><p><code class="docutils literal notranslate"><span class="pre">mp</span></code>: Pointer to memory pool </p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">block_addr</span></code>: Pointer to memory block</p></li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="c function">
<dt id="c.os_memblock_put">
<span class="target" id="group___o_s_mempool_1gaf6178bdc593729880d9d2bb7e23e11b0"></span><span class="pre">os_error_t</span> <code class="sig-name descname"><span class="pre">os_memblock_put</span></code><span class="sig-paren">(</span><em class="property"><span class="pre">struct</span></em> <a class="reference internal" href="#c.os_mempool" title="os_mempool"><span class="pre">os_mempool</span></a> <span class="pre">*</span><em><span class="pre">mp</span></em>, <span class="pre">void</span> <span class="pre">*</span><em><span class="pre">block_addr</span></em><span class="sig-paren">)</span><a class="headerlink" href="#c.os_memblock_put" title="Permalink to this definition"></a><br /></dt>
<dd><p>Puts the memory block back into the pool. </p>
<p><dl class="simple">
<dt><strong>Return</strong></dt><dd><p>os_error_t </p>
</dd>
<dt><strong>Parameters</strong></dt><dd><ul class="breatheparameterlist simple">
<li><p><code class="docutils literal notranslate"><span class="pre">mp</span></code>: Pointer to memory pool </p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">block_addr</span></code>: Pointer to memory block</p></li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="c macro">
<dt id="c.OS_MEMPOOL_F_EXT">
<span class="target" id="group___o_s_mempool_1gabc6a0dba610f01a2fcbedb9902f98260"></span><code class="sig-name descname"><span class="pre">OS_MEMPOOL_F_EXT</span></code><a class="headerlink" href="#c.OS_MEMPOOL_F_EXT" title="Permalink to this definition"></a><br /></dt>
<dd><p>Indicates an extended mempool. </p>
<p>Address can be safely cast to (struct <a class="reference internal" href="#structos__mempool__ext"><span class="std std-ref">os_mempool_ext</span></a> *). </p>
</dd></dl>
<dl class="c macro">
<dt id="c.OS_MEMPOOL_INFO_NAME_LEN">
<span class="target" id="group___o_s_mempool_1gae23cbfc2e7590d009c651bce00a58d95"></span><code class="sig-name descname"><span class="pre">OS_MEMPOOL_INFO_NAME_LEN</span></code><a class="headerlink" href="#c.OS_MEMPOOL_INFO_NAME_LEN" title="Permalink to this definition"></a><br /></dt>
<dd></dd></dl>
<dl class="c macro">
<dt id="c.OS_MEMPOOL_SIZE">
<span class="target" id="group___o_s_mempool_1gac5014e0e9c9e52c42d228158e5fc92c6"></span><code class="sig-name descname"><span class="pre">OS_MEMPOOL_SIZE</span></code><span class="sig-paren">(</span><em><span class="pre">n</span></em>, <em><span class="pre">blksize</span></em><span class="sig-paren">)</span><a class="headerlink" href="#c.OS_MEMPOOL_SIZE" title="Permalink to this definition"></a><br /></dt>
<dd></dd></dl>
<dl class="c macro">
<dt id="c.OS_MEMPOOL_BYTES">
<span class="target" id="group___o_s_mempool_1ga7fa594c641e3c1143fc641e80c6029ee"></span><code class="sig-name descname"><span class="pre">OS_MEMPOOL_BYTES</span></code><span class="sig-paren">(</span><em><span class="pre">n</span></em>, <em><span class="pre">blksize</span></em><span class="sig-paren">)</span><a class="headerlink" href="#c.OS_MEMPOOL_BYTES" title="Permalink to this definition"></a><br /></dt>
<dd><p>Calculates the number of bytes required to initialize a memory pool. </p>
</dd></dl>
<dl class="c struct">
<dt id="c.os_memblock">
<span class="target" id="structos__memblock"></span><em class="property"><span class="pre">struct</span> </em><code class="sig-name descname"><span class="pre">os_memblock</span></code><a class="headerlink" href="#c.os_memblock" title="Permalink to this definition"></a><br /></dt>
<dd><em>#include &lt;os_mempool.h&gt;</em><p>A memory block structure. </p>
<p>This simply contains a pointer to the free list chain and is only used when the block is on the free list. When the block has been removed from the free list the entire memory block is usable by the caller. </p>
</dd></dl>
<dl class="c struct">
<dt id="c.os_mempool">
<span class="target" id="structos__mempool"></span><em class="property"><span class="pre">struct</span> </em><code class="sig-name descname"><span class="pre">os_mempool</span></code><a class="headerlink" href="#c.os_mempool" title="Permalink to this definition"></a><br /></dt>
<dd><em>#include &lt;os_mempool.h&gt;</em><p>Memory pool. </p>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric" id="breathe-section-title-public-members">Public Members</p>
<dl class="c var">
<dt id="c.os_mempool.mp_block_size">
<span class="target" id="structos__mempool_1aa8b69c7241eef307bfdab6558f7a76fc"></span><span class="pre">uint32_t</span> <code class="sig-name descname"><span class="pre">mp_block_size</span></code><a class="headerlink" href="#c.os_mempool.mp_block_size" title="Permalink to this definition"></a><br /></dt>
<dd><p>Size of the memory blocks, in bytes. </p>
</dd></dl>
<dl class="c var">
<dt id="c.os_mempool.mp_num_blocks">
<span class="target" id="structos__mempool_1a1070d64ec9462682b859afa551dc4f7d"></span><span class="pre">uint16_t</span> <code class="sig-name descname"><span class="pre">mp_num_blocks</span></code><a class="headerlink" href="#c.os_mempool.mp_num_blocks" title="Permalink to this definition"></a><br /></dt>
<dd><p>The number of memory blocks. </p>
</dd></dl>
<dl class="c var">
<dt id="c.os_mempool.mp_num_free">
<span class="target" id="structos__mempool_1a330c95fc173c50c2c724d044e3260eaa"></span><span class="pre">uint16_t</span> <code class="sig-name descname"><span class="pre">mp_num_free</span></code><a class="headerlink" href="#c.os_mempool.mp_num_free" title="Permalink to this definition"></a><br /></dt>
<dd><p>The number of free blocks left. </p>
</dd></dl>
<dl class="c var">
<dt id="c.os_mempool.mp_min_free">
<span class="target" id="structos__mempool_1adcae8c4d47359ce32b49e112f925a53f"></span><span class="pre">uint16_t</span> <code class="sig-name descname"><span class="pre">mp_min_free</span></code><a class="headerlink" href="#c.os_mempool.mp_min_free" title="Permalink to this definition"></a><br /></dt>
<dd><p>The lowest number of free blocks seen. </p>
</dd></dl>
<dl class="c var">
<dt id="c.os_mempool.mp_flags">
<span class="target" id="structos__mempool_1a08fe88157701d4a1ec6162a8292e1b50"></span><span class="pre">uint8_t</span> <code class="sig-name descname"><span class="pre">mp_flags</span></code><a class="headerlink" href="#c.os_mempool.mp_flags" title="Permalink to this definition"></a><br /></dt>
<dd><p>Bitmap of OS_MEMPOOL_F_[…] values. </p>
</dd></dl>
<dl class="c var">
<dt id="c.os_mempool.mp_membuf_addr">
<span class="target" id="structos__mempool_1ac61a68914819ed8a178fbc9dda26b8d0"></span><span class="pre">uint32_t</span> <code class="sig-name descname"><span class="pre">mp_membuf_addr</span></code><a class="headerlink" href="#c.os_mempool.mp_membuf_addr" title="Permalink to this definition"></a><br /></dt>
<dd><p>Address of memory buffer used by pool. </p>
</dd></dl>
<dl class="c var">
<dt id="c.os_mempool.name">
<span class="target" id="structos__mempool_1ac10eae51516dfaa843213b7c154cb92d"></span><span class="pre">char</span> <span class="pre">*</span><code class="sig-name descname"><span class="pre">name</span></code><a class="headerlink" href="#c.os_mempool.name" title="Permalink to this definition"></a><br /></dt>
<dd><p>Name for memory block. </p>
</dd></dl>
</div>
</dd></dl>
<dl class="c struct">
<dt id="c.os_mempool_ext">
<span class="target" id="structos__mempool__ext"></span><em class="property"><span class="pre">struct</span> </em><code class="sig-name descname"><span class="pre">os_mempool_ext</span></code><a class="headerlink" href="#c.os_mempool_ext" title="Permalink to this definition"></a><br /></dt>
<dd><em>#include &lt;os_mempool.h&gt;</em></dd></dl>
<dl class="c struct">
<dt id="c.os_mempool_info">
<span class="target" id="structos__mempool__info"></span><em class="property"><span class="pre">struct</span> </em><code class="sig-name descname"><span class="pre">os_mempool_info</span></code><a class="headerlink" href="#c.os_mempool_info" title="Permalink to this definition"></a><br /></dt>
<dd><em>#include &lt;os_mempool.h&gt;</em><p>Information describing a memory pool, used to return OS information to the management layer. </p>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric" id="breathe-section-title-public-members">Public Members</p>
<dl class="c var">
<dt id="c.os_mempool_info.omi_block_size">
<span class="target" id="structos__mempool__info_1afe44d778f68b1ac45af5bfa4a21e7a03"></span><span class="pre">int</span> <code class="sig-name descname"><span class="pre">omi_block_size</span></code><a class="headerlink" href="#c.os_mempool_info.omi_block_size" title="Permalink to this definition"></a><br /></dt>
<dd><p>Size of the memory blocks in the pool. </p>
</dd></dl>
<dl class="c var">
<dt id="c.os_mempool_info.omi_num_blocks">
<span class="target" id="structos__mempool__info_1a396fcdd3a698a8df11dc848a3ea44006"></span><span class="pre">int</span> <code class="sig-name descname"><span class="pre">omi_num_blocks</span></code><a class="headerlink" href="#c.os_mempool_info.omi_num_blocks" title="Permalink to this definition"></a><br /></dt>
<dd><p>Number of memory blocks in the pool. </p>
</dd></dl>
<dl class="c var">
<dt id="c.os_mempool_info.omi_num_free">
<span class="target" id="structos__mempool__info_1adeec12d679ad4825c39aa615aecdf2b7"></span><span class="pre">int</span> <code class="sig-name descname"><span class="pre">omi_num_free</span></code><a class="headerlink" href="#c.os_mempool_info.omi_num_free" title="Permalink to this definition"></a><br /></dt>
<dd><p>Number of free memory blocks. </p>
</dd></dl>
<dl class="c var">
<dt id="c.os_mempool_info.omi_min_free">
<span class="target" id="structos__mempool__info_1a2dea3179c694145c6d7d478529968548"></span><span class="pre">int</span> <code class="sig-name descname"><span class="pre">omi_min_free</span></code><a class="headerlink" href="#c.os_mempool_info.omi_min_free" title="Permalink to this definition"></a><br /></dt>
<dd><p>Minimum number of free memory blocks ever. </p>
</dd></dl>
<dl class="c var">
<dt id="c.os_mempool_info.omi_name">
<span class="target" id="structos__mempool__info_1a616071f643a7cc73b1564cf7b76fc052"></span><span class="pre">char</span> <code class="sig-name descname"><span class="pre">omi_name</span></code><span class="pre">[</span><code class="sig-name descname"><span class="pre">OS_MEMPOOL_INFO_NAME_LEN</span></code><span class="pre">]</span><a class="headerlink" href="#c.os_mempool_info.omi_name" title="Permalink to this definition"></a><br /></dt>
<dd><p>Name of the memory pool. </p>
</dd></dl>
</div>
</dd></dl>
</div>
</div>
</div>
</div>
<div class="rst-footer-buttons row" role="navigation" aria-label="footer navigation">
<a href="../mbuf/mbuf.html" class="btn btn-neutral float-right" title="Mbufs" accesskey="n">Next: Mbufs <span class="fa fa-arrow-circle-right"></span></a>
<a href="../heap/heap.html" class="btn btn-neutral" title="Heap" accesskey="p"><span class="fa fa-arrow-circle-left"></span> Previous: Heap</a>
</div>
</div>
</div>
</div>
<!-- ENDS CONTENT SECTION -->
</div>
<!-- ENDS .content -->
</div>
</div>
<footer>
<div class="container">
<div class="row">
<div class="col-xs-12">
<p class="copyright">Apache Mynewt is available under Apache License, version 2.0.</p>
</div>
<div class="col-xs-12">
<div class="logos">
<img src="../../../_static/img/asf_logo_wide_small.png" alt="Apache" title="Apache">
<small class="footnote">
Apache Mynewt, Mynewt, Apache, the Apache feather logo, and the Apache Mynewt project logo are either
registered trademarks or trademarks of the Apache Software Foundation in the United States and other countries.
</small>
<a href="">
<img src="../../../_static/img/add_to_slack.png" alt="Slack Icon" title="Join our Slack Community" />
</a>
</div>
</div>
</div>
</div>
</footer>
</div>
<!-- ENDS #wrapper -->
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT:'../../../',
VERSION:'latest',
COLLAPSE_INDEX:false,
FILE_SUFFIX:'.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: '.txt',
LINK_SUFFIX: '.html'
};
</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>
<script type="text/javascript" src="../../../_static/js/bootstrap-3.0.3.min.js"></script>
<script type="text/javascript" src="../../../_static/js/affix.js"></script>
<script type="text/javascript" src="../../../_static/js/main.js"></script>
</body>
</html>