<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><aclass="el"href="chconf_8h.html"title="Configuration file template.">chconf.h</a></code>. </p>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Initializes the default heap. <ahref="#ga7e7a6625a49b6a560a47ae7575575264"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Initializes a memory heap from a static memory area. <ahref="#ga7135c9ddbd1402a4a36ce44df948f4e4"></a><br/></td></tr>
<tr><tdclass="mdescLeft"> </td><tdclass="mdescRight">Allocates a block of memory from the heap by using the first-fit algorithm. <ahref="#ga3d364eec0bef8b1986f63b3288ebbd5f"></a><br/></td></tr>
<areashape="rect"id="node3"href="group__mutexes.html#gac55fe4d05aa6bbeb31594193d2e4d2b6"title="Initializes s Mutex structure."alt=""coords="123,5,187,32"/><areashape="rect"id="node5"href="group__semaphores.html#gafe8fc6155a871074e8017efd908b2c58"title="Initializes a semaphore with the specified counter value."alt=""coords="121,56,188,83"/></map>
<p>Initializes a memory heap from a static memory area. </p>
<dlclass="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>
<tableborder="0"cellspacing="2"cellpadding="0">
<tr><tdvalign="top"><tt>[out]</tt> </td><tdvalign="top"><em>heapp</em> </td><td>pointer to the memory heap descriptor to be initialized </td></tr>
<tr><tdvalign="top"><tt>[in]</tt> </td><tdvalign="top"><em>buf</em> </td><td>heap buffer base </td></tr>
<areashape="rect"id="node3"href="group__mutexes.html#gac55fe4d05aa6bbeb31594193d2e4d2b6"title="Initializes s Mutex structure."alt=""coords="128,5,192,32"/><areashape="rect"id="node5"href="group__semaphores.html#gafe8fc6155a871074e8017efd908b2c58"title="Initializes a semaphore with the specified counter value."alt=""coords="127,56,193,83"/></map>
<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>
<tableborder="0"cellspacing="2"cellpadding="0">
<tr><tdvalign="top"><tt>[in]</tt> </td><tdvalign="top"><em>heapp</em> </td><td>pointer to a heap descriptor or <code>NULL</code> in order to access the default heap. </td></tr>
<tr><tdvalign="top"><tt>[in]</tt> </td><tdvalign="top"><em>size</em> </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>
<dlclass="return"><dt><b>Returns:</b></dt><dd>A pointer to the allocated block. </dd></dl>
<dl><dt><b>Return values:</b></dt><dd>
<tableborder="0"cellspacing="2"cellpadding="0">
<tr><tdvalign="top"></td><tdvalign="top"><em>NULL</em> </td><td>if the block cannot be allocated. </td></tr>
</table>
</dd>
</dl>
<p>Definition at line <aclass="el"href="chheap_8c_source.html#l00124">124</a> of file <aclass="el"href="chheap_8c_source.html">chheap.c</a>.</p>
<p>References <aclass="el"href="structmemory__heap.html#a77ba7416411ebd49578c71bca15d19ae">memory_heap::h_free</a>, <aclass="el"href="structmemory__heap.html#a4cad69cd924f2de313510634d2f6de1e">memory_heap::h_provider</a>, <aclass="el"href="group__memcore.html#ga216a7738be23e0caa9d18e510eb795eb">MEM_ALIGN_SIZE</a>, <aclass="el"href="unionheap__header.html#a591d8bde47aea2ab624cdde2cf2587ac">heap_header::size</a>, and <aclass="el"href="unionheap__header.html#a5bf3372839178fcc710e37d64f561e06">heap_header::u</a>.</p>
<p>Referenced by <aclass="el"href="group__threads.html#ga50b84e3e82a4e09c1066e1d422e4c780">chThdCreateFromHeap()</a>.</p>
<dlclass="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>
<tableborder="0"cellspacing="2"cellpadding="0">
<tr><tdvalign="top"><tt>[in]</tt> </td><tdvalign="top"><em>heapp</em> </td><td>pointer to a heap descriptor or <code>NULL</code> in order to access the default heap. </td></tr>
<tr><tdvalign="top"><tt>[in]</tt> </td><tdvalign="top"><em>sizep</em> </td><td>pointer to a variable that will receive the total fragmented free space </td></tr>
</table>
</dd>
</dl>
<dlclass="return"><dt><b>Returns:</b></dt><dd>The number of fragments in the heap. </dd></dl>
<p>Definition at line <aclass="el"href="chheap_8c_source.html#l00238">238</a> of file <aclass="el"href="chheap_8c_source.html">chheap.c</a>.</p>
<p>References <aclass="el"href="structmemory__heap.html#a77ba7416411ebd49578c71bca15d19ae">memory_heap::h_free</a>, and <aclass="el"href="unionheap__header.html#a5bf3372839178fcc710e37d64f561e06">heap_header::u</a>.</p>
Generated on Sun Oct 24 2010 09:40:46 for ChibiOS/RT by <ahref="http://www.doxygen.org/index.html"><imgsrc="doxygen.png"alt="doxygen"align="middle"border="0"></a> 1.7.1</small></address>