gnuk/ChibiOS_2.0.8/docs/html/group__heaps.html
2010-11-30 13:54:43 +09:00

301 lines
18 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>ChibiOS/RT: Heaps</title>
<link href="custom.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<table style="text-align: center; width: 100%;" border="0"
cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="width: 80px;"><img alt="ChibiOS/RT Logo" src="logo_small.png"></td>
<td><big><big>ChibiOS/RT</big></big><br><br>Architecture - Reference Manual - Guides</td>
<td style="width: 80px;"></td>
</tr>
</tbody>
</table>
<hr size="1">
<!-- Generated by Doxygen 1.7.1 -->
<div class="navigation" id="top">
<div class="tabs">
<ul class="tablist">
<li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
<li><a href="modules.html"><span>Modules</span></a></li>
<li><a href="annotated.html"><span>Data&nbsp;Structures</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
</ul>
</div>
</div>
<div class="header">
<div class="summary">
<a href="#nested-classes">Data Structures</a> &#124;
<a href="#func-members">Functions</a> </div>
<div class="headertitle">
<h1>Heaps<br/>
<small>
[<a class="el" href="group__memory.html">Memory Management</a>]</small>
</h1> </div>
</div>
<div class="contents">
<p><div class="dynheader">
Collaboration diagram for Heaps:</div>
<div class="dyncontent">
<center><table><tr><td><img src="group__heaps.png" border="0" alt="" usemap="#group____heaps"/>
<map name="group____heaps" id="group____heaps">
<area shape="rect" id="node2" href="group__memory.html" title="Memory Management" alt="" coords="7,5,129,32"/>
</map>
</td></tr></table></center>
</div>
</p>
<hr/><a name="_details"></a><h2>Description</h2>
<p>Heap Allocator related APIs. </p>
<h2>Operation mode</h2>
<p>The heap allocator implements a first-fit strategy and its APIs are functionally equivalent to the usual <code>malloc()</code> and <code>free()</code> library functions. The main difference is that the OS heap APIs are guaranteed to be thread safe.<br/>
By enabling the <code>CH_USE_MALLOC_HEAP</code> option the heap manager will use the runtime-provided <code>malloc()</code> and <code>free()</code> as backend for the heap APIs instead of the system provided allocator.<br/>
In order to use the heap APIs the <code>CH_USE_HEAP</code> option must be enabled in <code><a class="el" href="chconf_8h.html" title="Configuration file template.">chconf.h</a></code>. </p>
<table class="memberdecls">
<tr><td colspan="2"><h2><a name="nested-classes"></a>
Data Structures</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">union &nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="unionheap__header.html">heap_header</a></td></tr>
<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Memory heap block header. <a href="unionheap__header.html#_details">More...</a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">struct &nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="structmemory__heap.html">memory_heap</a></td></tr>
<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Structure describing a memory heap. <a href="structmemory__heap.html#_details">More...</a><br/></td></tr>
<tr><td colspan="2"><h2><a name="func-members"></a>
Functions</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__heaps.html#ga7e7a6625a49b6a560a47ae7575575264">heap_init</a> (void)</td></tr>
<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Initializes the default heap. <a href="#ga7e7a6625a49b6a560a47ae7575575264"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__heaps.html#ga7135c9ddbd1402a4a36ce44df948f4e4">chHeapInit</a> (<a class="el" href="structmemory__heap.html">MemoryHeap</a> *heapp, void *buf, size_t size)</td></tr>
<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Initializes a memory heap from a static memory area. <a href="#ga7135c9ddbd1402a4a36ce44df948f4e4"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void *&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__heaps.html#ga3d364eec0bef8b1986f63b3288ebbd5f">chHeapAlloc</a> (<a class="el" href="structmemory__heap.html">MemoryHeap</a> *heapp, size_t size)</td></tr>
<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Allocates a block of memory from the heap by using the first-fit algorithm. <a href="#ga3d364eec0bef8b1986f63b3288ebbd5f"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__heaps.html#ga0fc553df0138f02e0b233be91e413c79">chHeapFree</a> (void *p)</td></tr>
<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Frees a previously allocated memory block. <a href="#ga0fc553df0138f02e0b233be91e413c79"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">size_t&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__heaps.html#ga944ffb8c5b83c26b984e6a072d871a8b">chHeapStatus</a> (<a class="el" href="structmemory__heap.html">MemoryHeap</a> *heapp, size_t *sizep)</td></tr>
<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Reports the heap status. <a href="#ga944ffb8c5b83c26b984e6a072d871a8b"></a><br/></td></tr>
</table>
<hr/><h2>Function Documentation</h2>
<a class="anchor" id="ga7e7a6625a49b6a560a47ae7575575264"></a><!-- doxytag: member="chheap.h::heap_init" ref="ga7e7a6625a49b6a560a47ae7575575264" args="(void)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void heap_init </td>
<td>(</td>
<td class="paramtype">void&nbsp;</td>
<td class="paramname"></td>
<td>&nbsp;)&nbsp;</td>
<td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Initializes the default heap. </p>
<dl class="note"><dt><b>Note:</b></dt><dd>Internal use only. </dd></dl>
<p>Definition at line <a class="el" href="chheap_8c_source.html#l00073">73</a> of file <a class="el" href="chheap_8c_source.html">chheap.c</a>.</p>
<p>References <a class="el" href="group__mutexes.html#gac55fe4d05aa6bbeb31594193d2e4d2b6">chMtxInit()</a>, <a class="el" href="group__semaphores.html#gafe8fc6155a871074e8017efd908b2c58">chSemInit()</a>, <a class="el" href="structmemory__heap.html#a77ba7416411ebd49578c71bca15d19ae">memory_heap::h_free</a>, <a class="el" href="structmemory__heap.html#aa7eafd71c17c8175c2c7662685777fb5">memory_heap::h_mtx</a>, <a class="el" href="structmemory__heap.html#a4cad69cd924f2de313510634d2f6de1e">memory_heap::h_provider</a>, <a class="el" href="unionheap__header.html#a591d8bde47aea2ab624cdde2cf2587ac">heap_header::size</a>, and <a class="el" href="unionheap__header.html#a5bf3372839178fcc710e37d64f561e06">heap_header::u</a>.</p>
<p>Referenced by <a class="el" href="group__system.html#gafe2c7de6567e98e487e009e81e3be10b">chSysInit()</a>.</p>
<p><div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
<div class="center"><img src="group__heaps_ga7e7a6625a49b6a560a47ae7575575264_cgraph.png" border="0" usemap="#group__heaps_ga7e7a6625a49b6a560a47ae7575575264_cgraph" alt=""/></div>
<map name="group__heaps_ga7e7a6625a49b6a560a47ae7575575264_cgraph" id="group__heaps_ga7e7a6625a49b6a560a47ae7575575264_cgraph">
<area shape="rect" id="node3" href="group__mutexes.html#gac55fe4d05aa6bbeb31594193d2e4d2b6" title="Initializes s Mutex structure." alt="" coords="123,5,187,32"/>
<area shape="rect" id="node5" href="group__semaphores.html#gafe8fc6155a871074e8017efd908b2c58" title="Initializes a semaphore with the specified counter value." alt="" coords="121,56,188,83"/>
</map>
</div>
</p>
</div>
</div>
<a class="anchor" id="ga7135c9ddbd1402a4a36ce44df948f4e4"></a><!-- doxytag: member="chheap.h::chHeapInit" ref="ga7135c9ddbd1402a4a36ce44df948f4e4" args="(MemoryHeap *heapp, void *buf, size_t size)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void chHeapInit </td>
<td>(</td>
<td class="paramtype"><a class="el" href="structmemory__heap.html">MemoryHeap</a> *&nbsp;</td>
<td class="paramname"> <em>heapp</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">void *&nbsp;</td>
<td class="paramname"> <em>buf</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t&nbsp;</td>
<td class="paramname"> <em>size</em></td><td>&nbsp;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td><td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Initializes a memory heap from a static memory area. </p>
<dl class="note"><dt><b>Note:</b></dt><dd>Both the heap buffer base and the heap size must be aligned to the <code>align_t</code> type size.</dd></dl>
<dl><dt><b>Parameters:</b></dt><dd>
<table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"><tt>[out]</tt>&nbsp;</td><td valign="top"><em>heapp</em>&nbsp;</td><td>pointer to the memory heap descriptor to be initialized </td></tr>
<tr><td valign="top"><tt>[in]</tt>&nbsp;</td><td valign="top"><em>buf</em>&nbsp;</td><td>heap buffer base </td></tr>
<tr><td valign="top"><tt>[in]</tt>&nbsp;</td><td valign="top"><em>size</em>&nbsp;</td><td>heap size </td></tr>
</table>
</dd>
</dl>
<p>Definition at line <a class="el" href="chheap_8c_source.html#l00093">93</a> of file <a class="el" href="chheap_8c_source.html">chheap.c</a>.</p>
<p>References <a class="el" href="group__debug.html#ga6bb6c0f97caab3a66332c8bfbf7a3844">chDbgCheck</a>, <a class="el" href="group__mutexes.html#gac55fe4d05aa6bbeb31594193d2e4d2b6">chMtxInit()</a>, <a class="el" href="group__semaphores.html#gafe8fc6155a871074e8017efd908b2c58">chSemInit()</a>, <a class="el" href="structmemory__heap.html#a77ba7416411ebd49578c71bca15d19ae">memory_heap::h_free</a>, <a class="el" href="structmemory__heap.html#aa7eafd71c17c8175c2c7662685777fb5">memory_heap::h_mtx</a>, <a class="el" href="structmemory__heap.html#a4cad69cd924f2de313510634d2f6de1e">memory_heap::h_provider</a>, <a class="el" href="group__memcore.html#gac38a64d9001b24d62f1c9ab79fbc328b">MEM_IS_ALIGNED</a>, <a class="el" href="unionheap__header.html#a591d8bde47aea2ab624cdde2cf2587ac">heap_header::size</a>, and <a class="el" href="unionheap__header.html#a5bf3372839178fcc710e37d64f561e06">heap_header::u</a>.</p>
<p><div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
<div class="center"><img src="group__heaps_ga7135c9ddbd1402a4a36ce44df948f4e4_cgraph.png" border="0" usemap="#group__heaps_ga7135c9ddbd1402a4a36ce44df948f4e4_cgraph" alt=""/></div>
<map name="group__heaps_ga7135c9ddbd1402a4a36ce44df948f4e4_cgraph" id="group__heaps_ga7135c9ddbd1402a4a36ce44df948f4e4_cgraph">
<area shape="rect" id="node3" href="group__mutexes.html#gac55fe4d05aa6bbeb31594193d2e4d2b6" title="Initializes s Mutex structure." alt="" coords="128,5,192,32"/>
<area shape="rect" id="node5" href="group__semaphores.html#gafe8fc6155a871074e8017efd908b2c58" title="Initializes a semaphore with the specified counter value." alt="" coords="127,56,193,83"/>
</map>
</div>
</p>
</div>
</div>
<a class="anchor" id="ga3d364eec0bef8b1986f63b3288ebbd5f"></a><!-- doxytag: member="chheap.h::chHeapAlloc" ref="ga3d364eec0bef8b1986f63b3288ebbd5f" args="(MemoryHeap *heapp, size_t size)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void * chHeapAlloc </td>
<td>(</td>
<td class="paramtype"><a class="el" href="structmemory__heap.html">MemoryHeap</a> *&nbsp;</td>
<td class="paramname"> <em>heapp</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t&nbsp;</td>
<td class="paramname"> <em>size</em></td><td>&nbsp;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td><td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Allocates a block of memory from the heap by using the first-fit algorithm. </p>
<p>The allocated block is guaranteed to be properly aligned for a pointer data type (<code>align_t</code>).</p>
<dl><dt><b>Parameters:</b></dt><dd>
<table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"><tt>[in]</tt>&nbsp;</td><td valign="top"><em>heapp</em>&nbsp;</td><td>pointer to a heap descriptor or <code>NULL</code> in order to access the default heap. </td></tr>
<tr><td valign="top"><tt>[in]</tt>&nbsp;</td><td valign="top"><em>size</em>&nbsp;</td><td>the size of the block to be allocated. Note that the allocated block may be a bit bigger than the requested size for alignment and fragmentation reasons. </td></tr>
</table>
</dd>
</dl>
<dl class="return"><dt><b>Returns:</b></dt><dd>A pointer to the allocated block. </dd></dl>
<dl><dt><b>Return values:</b></dt><dd>
<table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"></td><td valign="top"><em>NULL</em>&nbsp;</td><td>if the block cannot be allocated. </td></tr>
</table>
</dd>
</dl>
<p>Definition at line <a class="el" href="chheap_8c_source.html#l00124">124</a> of file <a class="el" href="chheap_8c_source.html">chheap.c</a>.</p>
<p>References <a class="el" href="structmemory__heap.html#a77ba7416411ebd49578c71bca15d19ae">memory_heap::h_free</a>, <a class="el" href="structmemory__heap.html#a4cad69cd924f2de313510634d2f6de1e">memory_heap::h_provider</a>, <a class="el" href="group__memcore.html#ga216a7738be23e0caa9d18e510eb795eb">MEM_ALIGN_SIZE</a>, <a class="el" href="unionheap__header.html#a591d8bde47aea2ab624cdde2cf2587ac">heap_header::size</a>, and <a class="el" href="unionheap__header.html#a5bf3372839178fcc710e37d64f561e06">heap_header::u</a>.</p>
<p>Referenced by <a class="el" href="group__threads.html#ga50b84e3e82a4e09c1066e1d422e4c780">chThdCreateFromHeap()</a>.</p>
</div>
</div>
<a class="anchor" id="ga0fc553df0138f02e0b233be91e413c79"></a><!-- doxytag: member="chheap.h::chHeapFree" ref="ga0fc553df0138f02e0b233be91e413c79" args="(void *p)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void chHeapFree </td>
<td>(</td>
<td class="paramtype">void *&nbsp;</td>
<td class="paramname"> <em>p</em></td>
<td>&nbsp;)&nbsp;</td>
<td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Frees a previously allocated memory block. </p>
<dl><dt><b>Parameters:</b></dt><dd>
<table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"><tt>[in]</tt>&nbsp;</td><td valign="top"><em>p</em>&nbsp;</td><td>pointer to the memory block to be freed </td></tr>
</table>
</dd>
</dl>
<p>Definition at line <a class="el" href="chheap_8c_source.html#l00184">184</a> of file <a class="el" href="chheap_8c_source.html">chheap.c</a>.</p>
<p>References <a class="el" href="group__debug.html#ga43d50c69eb730d0f024eb832d61f30c9">chDbgAssert</a>, <a class="el" href="group__debug.html#ga6bb6c0f97caab3a66332c8bfbf7a3844">chDbgCheck</a>, <a class="el" href="structmemory__heap.html#a77ba7416411ebd49578c71bca15d19ae">memory_heap::h_free</a>, <a class="el" href="unionheap__header.html#a591d8bde47aea2ab624cdde2cf2587ac">heap_header::size</a>, and <a class="el" href="unionheap__header.html#a5bf3372839178fcc710e37d64f561e06">heap_header::u</a>.</p>
<p>Referenced by <a class="el" href="group__threads.html#gaa22f80040cf192015be4607f31a0ac80">chThdRelease()</a>.</p>
</div>
</div>
<a class="anchor" id="ga944ffb8c5b83c26b984e6a072d871a8b"></a><!-- doxytag: member="chheap.h::chHeapStatus" ref="ga944ffb8c5b83c26b984e6a072d871a8b" args="(MemoryHeap *heapp, size_t *sizep)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">size_t chHeapStatus </td>
<td>(</td>
<td class="paramtype"><a class="el" href="structmemory__heap.html">MemoryHeap</a> *&nbsp;</td>
<td class="paramname"> <em>heapp</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t *&nbsp;</td>
<td class="paramname"> <em>sizep</em></td><td>&nbsp;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td><td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Reports the heap status. </p>
<dl class="note"><dt><b>Note:</b></dt><dd>This function is meant to be used in the test suite, it should not be really useful for the application code. </dd>
<dd>
This function is not implemented when the <code>CH_USE_MALLOC_HEAP</code> configuration option is used (it always returns zero).</dd></dl>
<dl><dt><b>Parameters:</b></dt><dd>
<table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"><tt>[in]</tt>&nbsp;</td><td valign="top"><em>heapp</em>&nbsp;</td><td>pointer to a heap descriptor or <code>NULL</code> in order to access the default heap. </td></tr>
<tr><td valign="top"><tt>[in]</tt>&nbsp;</td><td valign="top"><em>sizep</em>&nbsp;</td><td>pointer to a variable that will receive the total fragmented free space </td></tr>
</table>
</dd>
</dl>
<dl class="return"><dt><b>Returns:</b></dt><dd>The number of fragments in the heap. </dd></dl>
<p>Definition at line <a class="el" href="chheap_8c_source.html#l00238">238</a> of file <a class="el" href="chheap_8c_source.html">chheap.c</a>.</p>
<p>References <a class="el" href="structmemory__heap.html#a77ba7416411ebd49578c71bca15d19ae">memory_heap::h_free</a>, and <a class="el" href="unionheap__header.html#a5bf3372839178fcc710e37d64f561e06">heap_header::u</a>.</p>
</div>
</div>
</div>
<hr size="1"><address style="text-align: right;"><small>
Generated on Sun Nov 28 2010 14:09:56 for ChibiOS/RT by&nbsp;<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.7.1</small></address>
</body>
</html>