<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <title>mrpt::system::CGenericMemoryPool Class Reference</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> <link href="tabs.css" rel="stylesheet" type="text/css"> </head><body> <div align="left"><a href="http://www.mrpt.org/">Main MRPT website</a> > <b>C++ reference</b> </div> <div align="right"> <a href="index.html"><img border="0" src="mrpt_logo.png" alt="MRPT logo"></a> </div> <!-- Generated by Doxygen 1.7.5 --> <script type="text/javascript"> var searchBox = new SearchBox("searchBox", "search",false,'Search'); </script> <div id="navrow1" class="tabs"> <ul class="tablist"> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> <li><a href="modules.html"><span>Modules</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li class="current"><a href="annotated.html"><span>Classes</span></a></li> <li><a href="files.html"><span>Files</span></a></li> <li> <div id="MSearchBox" class="MSearchBoxInactive"> <div class="left"> <form id="FSearchBox" action="search.php" method="get"> <img id="MSearchSelect" src="search/mag.png" alt=""/> <input type="text" id="MSearchField" name="query" value="Search" size="20" accesskey="S" onfocus="searchBox.OnSearchFieldFocus(true)" onblur="searchBox.OnSearchFieldFocus(false)"/> </form> </div><div class="right"></div> </div> </li> </ul> </div> <div id="navrow2" class="tabs2"> <ul class="tablist"> <li><a href="annotated.html"><span>Class List</span></a></li> <li><a href="classes.html"><span>Class Index</span></a></li> <li><a href="inherits.html"><span>Class Hierarchy</span></a></li> <li><a href="functions.html"><span>Class Members</span></a></li> </ul> </div> <div id="nav-path" class="navpath"> <ul> <li class="navelem"><a class="el" href="namespacemrpt.html">mrpt</a> </li> <li class="navelem"><a class="el" href="namespacemrpt_1_1system.html">system</a> </li> <li class="navelem"><a class="el" href="classmrpt_1_1system_1_1_c_generic_memory_pool.html">CGenericMemoryPool</a> </li> </ul> </div> </div> <div class="header"> <div class="summary"> <a href="#pub-methods">Public Member Functions</a> | <a href="#pub-static-methods">Static Public Member Functions</a> | <a href="#pri-types">Private Types</a> | <a href="#pri-methods">Private Member Functions</a> | <a href="#pri-attribs">Private Attributes</a> </div> <div class="headertitle"> <div class="title">mrpt::system::CGenericMemoryPool Class Reference<div class="ingroups"><a class="el" href="group__mrpt__memory.html">Memory utilities</a></div></div> </div> </div> <div class="contents"> <!-- doxytag: class="mrpt::system::CGenericMemoryPool" --><hr/><a name="details" id="details"></a><h2>Detailed Description</h2> <div class="textblock"><p>A generic system for versatile memory pooling. </p> <p>This class implements the singleton pattern so a unique instance exists for each combination of template parameters. All methods are thread-safe.</p> <p>Basic usage:</p> <ul> <li>When needed, call <em><a class="el" href="classmrpt_1_1system_1_1_c_generic_memory_pool.html#aa9bc4767dbd20ca6b0ab25a2b1736bd8" title="Request a block of data which fulfils the size requirements stated in params.">request_memory()</a></em> to check the availability of memory in the pool.<ul> <li>At your class destructor, donate the memory to the pool with <em><a class="el" href="classmrpt_1_1system_1_1_c_generic_memory_pool.html#a65604586556f626575a94e420bd74745" title="Saves the passed data block (characterized by params) to the pool.">dump_to_pool()</a></em>.</li> </ul> </li> </ul> <p>Notice that memory requests are checked against memory blocks in the pool via a user-defined function:</p> <p>bool POOLABLE_DATA::isSuitable(const POOLABLE_DATA & req) const { ... }</p> <p>For an example of how to handle a memory pool, see the class <a class="el" href="classmrpt_1_1slam_1_1_c_observation3_d_range_scan.html" title="Declares a class derived from "CObservation" that encapsules a 3D range scan measurement (e...">mrpt::slam::CObservation3DRangeScan</a></p> <dl><dt><b>Template Parameters:</b></dt><dd> <table class=""> <tr><td class="paramname">POOLABLE_DATA</td><td>A struct with user-defined objects which actually contain the memory blocks (e.g. one or more <a class="el" href="classstd_1_1vector.html" title="STL class.">std::vector</a>). </td></tr> <tr><td class="paramname">DATA_PARAMS</td><td>A struct with user information about each memory block (e.g. size of a <a class="el" href="classstd_1_1vector.html" title="STL class.">std::vector</a>) </td></tr> </table> </dd> </dl> </div> <p><code>#include <<a class="el" href="_c_generic_memory_pool_8h_source.html">mrpt/system/CGenericMemoryPool.h</a>></code></p> <p><a href="classmrpt_1_1system_1_1_c_generic_memory_pool-members.html">List of all members.</a></p> <table class="memberdecls"> <tr><td colspan="2"><h2><a name="pub-methods"></a> Public Member Functions</h2></td></tr> <tr><td class="memItemLeft" align="right" valign="top">size_t </td><td class="memItemRight" valign="bottom"><a class="el" href="classmrpt_1_1system_1_1_c_generic_memory_pool.html#aa71a80e3d32eb387188ba69797136a75">getMemoryPoolMaxSize</a> () const </td></tr> <tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="classmrpt_1_1system_1_1_c_generic_memory_pool.html#a3a7e4f1726cb557eb6191fb2aec1518a">setMemoryPoolMaxSize</a> (const size_t maxNumEntries)</td></tr> <tr><td class="memItemLeft" align="right" valign="top">POOLABLE_DATA * </td><td class="memItemRight" valign="bottom"><a class="el" href="classmrpt_1_1system_1_1_c_generic_memory_pool.html#aa9bc4767dbd20ca6b0ab25a2b1736bd8">request_memory</a> (const DATA_PARAMS &params)</td></tr> <tr><td class="mdescLeft"> </td><td class="mdescRight">Request a block of data which fulfils the size requirements stated in <em>params</em>. <a href="#aa9bc4767dbd20ca6b0ab25a2b1736bd8"></a><br/></td></tr> <tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="classmrpt_1_1system_1_1_c_generic_memory_pool.html#a65604586556f626575a94e420bd74745">dump_to_pool</a> (const DATA_PARAMS &params, POOLABLE_DATA *block)</td></tr> <tr><td class="mdescLeft"> </td><td class="mdescRight">Saves the passed data block (characterized by <em>params</em>) to the pool. <a href="#a65604586556f626575a94e420bd74745"></a><br/></td></tr> <tr><td class="memItemLeft" align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="classmrpt_1_1system_1_1_c_generic_memory_pool.html#a6be7432c38925ce4032a8719abcdb5d9">~CGenericMemoryPool</a> ()</td></tr> <tr><td colspan="2"><h2><a name="pub-static-methods"></a> Static Public Member Functions</h2></td></tr> <tr><td class="memItemLeft" align="right" valign="top">static <a class="el" href="classmrpt_1_1system_1_1_c_generic_memory_pool.html">CGenericMemoryPool</a><br class="typebreak"/> < DATA_PARAMS, POOLABLE_DATA > & </td><td class="memItemRight" valign="bottom"><a class="el" href="classmrpt_1_1system_1_1_c_generic_memory_pool.html#a09929bb7df16dca1091c47c76403dc6b">getInstance</a> ()</td></tr> <tr><td class="mdescLeft"> </td><td class="mdescRight">Singleton: Return the unique instance of this class for a given template arguments: <a href="#a09929bb7df16dca1091c47c76403dc6b"></a><br/></td></tr> <tr><td colspan="2"><h2><a name="pri-types"></a> Private Types</h2></td></tr> <tr><td class="memItemLeft" align="right" valign="top">typedef <a class="el" href="classstd_1_1list.html">std::list</a>< std::pair<br class="typebreak"/> < DATA_PARAMS, POOLABLE_DATA * > > </td><td class="memItemRight" valign="bottom"><a class="el" href="classmrpt_1_1system_1_1_c_generic_memory_pool.html#af7eab650913d4bc790385cb41640f632">TList</a></td></tr> <tr><td colspan="2"><h2><a name="pri-methods"></a> Private Member Functions</h2></td></tr> <tr><td class="memItemLeft" align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="classmrpt_1_1system_1_1_c_generic_memory_pool.html#aa3e23307db805123fe2590eaeb397ae3">CGenericMemoryPool</a> ()</td></tr> <tr><td colspan="2"><h2><a name="pri-attribs"></a> Private Attributes</h2></td></tr> <tr><td class="memItemLeft" align="right" valign="top"><a class="el" href="classmrpt_1_1system_1_1_c_generic_memory_pool.html#af7eab650913d4bc790385cb41640f632">TList</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="classmrpt_1_1system_1_1_c_generic_memory_pool.html#a348858ea7cc83f0413f33aed477f4453">m_pool</a></td></tr> <tr><td class="memItemLeft" align="right" valign="top"><a class="el" href="classmrpt_1_1synch_1_1_c_critical_section.html">mrpt::synch::CCriticalSection</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="classmrpt_1_1system_1_1_c_generic_memory_pool.html#a7927dc67b0bf6a1cab0f6aa26fd40f63">m_pool_cs</a></td></tr> <tr><td class="memItemLeft" align="right" valign="top">size_t </td><td class="memItemRight" valign="bottom"><a class="el" href="classmrpt_1_1system_1_1_c_generic_memory_pool.html#a2e0c767b602037d42612b835db6253fd">m_maxPoolEntries</a></td></tr> </table> <hr/><h2>Member Typedef Documentation</h2> <a class="anchor" id="af7eab650913d4bc790385cb41640f632"></a><!-- doxytag: member="mrpt::system::CGenericMemoryPool::TList" ref="af7eab650913d4bc790385cb41640f632" args="" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">typedef <a class="el" href="classstd_1_1list.html">std::list</a><std::pair<DATA_PARAMS,POOLABLE_DATA*> > <a class="el" href="classmrpt_1_1system_1_1_c_generic_memory_pool.html#af7eab650913d4bc790385cb41640f632">mrpt::system::CGenericMemoryPool::TList</a><code> [private]</code></td> </tr> </table> </div> <div class="memdoc"> <p>Definition at line <a class="el" href="_c_generic_memory_pool_8h_source.html#l00059">59</a> of file <a class="el" href="_c_generic_memory_pool_8h_source.html">CGenericMemoryPool.h</a>.</p> </div> </div> <hr/><h2>Constructor & Destructor Documentation</h2> <a class="anchor" id="aa3e23307db805123fe2590eaeb397ae3"></a><!-- doxytag: member="mrpt::system::CGenericMemoryPool::CGenericMemoryPool" ref="aa3e23307db805123fe2590eaeb397ae3" args="()" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">mrpt::system::CGenericMemoryPool::CGenericMemoryPool </td> <td>(</td> <td class="paramname"></td><td>)</td> <td><code> [inline, private]</code></td> </tr> </table> </div> <div class="memdoc"> <p>Definition at line <a class="el" href="_c_generic_memory_pool_8h_source.html#l00064">64</a> of file <a class="el" href="_c_generic_memory_pool_8h_source.html">CGenericMemoryPool.h</a>.</p> </div> </div> <a class="anchor" id="a6be7432c38925ce4032a8719abcdb5d9"></a><!-- doxytag: member="mrpt::system::CGenericMemoryPool::~CGenericMemoryPool" ref="a6be7432c38925ce4032a8719abcdb5d9" args="()" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">mrpt::system::CGenericMemoryPool::~CGenericMemoryPool </td> <td>(</td> <td class="paramname"></td><td>)</td> <td><code> [inline]</code></td> </tr> </table> </div> <div class="memdoc"> <p>Definition at line <a class="el" href="_c_generic_memory_pool_8h_source.html#l00115">115</a> of file <a class="el" href="_c_generic_memory_pool_8h_source.html">CGenericMemoryPool.h</a>.</p> <p>References <a class="el" href="_c_generic_memory_pool_8h_source.html#l00061">m_pool_cs</a>, and <a class="el" href="_c_generic_memory_pool_8h_source.html#l00060">m_pool</a>.</p> </div> </div> <hr/><h2>Member Function Documentation</h2> <a class="anchor" id="a65604586556f626575a94e420bd74745"></a><!-- doxytag: member="mrpt::system::CGenericMemoryPool::dump_to_pool" ref="a65604586556f626575a94e420bd74745" args="(const DATA_PARAMS &params, POOLABLE_DATA *block)" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">void mrpt::system::CGenericMemoryPool::dump_to_pool </td> <td>(</td> <td class="paramtype">const DATA_PARAMS & </td> <td class="paramname"><em>params</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype">POOLABLE_DATA * </td> <td class="paramname"><em>block</em> </td> </tr> <tr> <td></td> <td>)</td> <td></td><td><code> [inline]</code></td> </tr> </table> </div> <div class="memdoc"> <p>Saves the passed data block (characterized by <em>params</em>) to the pool. </p> <p>If the overall size of the pool is above the limit, the oldest entry is removed. </p> <dl class="note"><dt><b>Note:</b></dt><dd>It is a responsibility of the user to allocate in dynamic memory the "POOLABLE_DATA" object with "new". </dd></dl> <p>Definition at line <a class="el" href="_c_generic_memory_pool_8h_source.html#l00105">105</a> of file <a class="el" href="_c_generic_memory_pool_8h_source.html">CGenericMemoryPool.h</a>.</p> <p>References <a class="el" href="_c_generic_memory_pool_8h_source.html#l00061">m_pool_cs</a>, <a class="el" href="_c_generic_memory_pool_8h_source.html#l00060">m_pool</a>, and <a class="el" href="_c_generic_memory_pool_8h_source.html#l00062">m_maxPoolEntries</a>.</p> </div> </div> <a class="anchor" id="a09929bb7df16dca1091c47c76403dc6b"></a><!-- doxytag: member="mrpt::system::CGenericMemoryPool::getInstance" ref="a09929bb7df16dca1091c47c76403dc6b" args="()" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">static <a class="el" href="classmrpt_1_1system_1_1_c_generic_memory_pool.html">CGenericMemoryPool</a><DATA_PARAMS,POOLABLE_DATA>& mrpt::system::CGenericMemoryPool::getInstance </td> <td>(</td> <td class="paramname"></td><td>)</td> <td><code> [inline, static]</code></td> </tr> </table> </div> <div class="memdoc"> <p>Singleton: Return the unique instance of this class for a given template arguments: </p> <p>Definition at line <a class="el" href="_c_generic_memory_pool_8h_source.html#l00073">73</a> of file <a class="el" href="_c_generic_memory_pool_8h_source.html">CGenericMemoryPool.h</a>.</p> </div> </div> <a class="anchor" id="aa71a80e3d32eb387188ba69797136a75"></a><!-- doxytag: member="mrpt::system::CGenericMemoryPool::getMemoryPoolMaxSize" ref="aa71a80e3d32eb387188ba69797136a75" args="() const " --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">size_t mrpt::system::CGenericMemoryPool::getMemoryPoolMaxSize </td> <td>(</td> <td class="paramname"></td><td>)</td> <td> const<code> [inline]</code></td> </tr> </table> </div> <div class="memdoc"> <p>Definition at line <a class="el" href="_c_generic_memory_pool_8h_source.html#l00069">69</a> of file <a class="el" href="_c_generic_memory_pool_8h_source.html">CGenericMemoryPool.h</a>.</p> <p>References <a class="el" href="_c_generic_memory_pool_8h_source.html#l00062">m_maxPoolEntries</a>.</p> </div> </div> <a class="anchor" id="aa9bc4767dbd20ca6b0ab25a2b1736bd8"></a><!-- doxytag: member="mrpt::system::CGenericMemoryPool::request_memory" ref="aa9bc4767dbd20ca6b0ab25a2b1736bd8" args="(const DATA_PARAMS &params)" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">POOLABLE_DATA* mrpt::system::CGenericMemoryPool::request_memory </td> <td>(</td> <td class="paramtype">const DATA_PARAMS & </td> <td class="paramname"><em>params</em></td><td>)</td> <td><code> [inline]</code></td> </tr> </table> </div> <div class="memdoc"> <p>Request a block of data which fulfils the size requirements stated in <em>params</em>. </p> <p>Notice that the decision on the suitability of each pool'ed block is done by DATA_PARAMS::isSuitable(). </p> <dl class="return"><dt><b>Returns:</b></dt><dd>The block of data, or NULL if none suitable was found in the pool. </dd></dl> <dl class="note"><dt><b>Note:</b></dt><dd>It is a responsibility of the user to free with "delete" the "POOLABLE_DATA" object itself once the memory has been extracted from its elements. </dd></dl> <p>Definition at line <a class="el" href="_c_generic_memory_pool_8h_source.html#l00084">84</a> of file <a class="el" href="_c_generic_memory_pool_8h_source.html">CGenericMemoryPool.h</a>.</p> <p>References <a class="el" href="_c_generic_memory_pool_8h_source.html#l00060">m_pool</a>, and <a class="el" href="_c_generic_memory_pool_8h_source.html#l00061">m_pool_cs</a>.</p> </div> </div> <a class="anchor" id="a3a7e4f1726cb557eb6191fb2aec1518a"></a><!-- doxytag: member="mrpt::system::CGenericMemoryPool::setMemoryPoolMaxSize" ref="a3a7e4f1726cb557eb6191fb2aec1518a" args="(const size_t maxNumEntries)" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">void mrpt::system::CGenericMemoryPool::setMemoryPoolMaxSize </td> <td>(</td> <td class="paramtype">const size_t </td> <td class="paramname"><em>maxNumEntries</em></td><td>)</td> <td><code> [inline]</code></td> </tr> </table> </div> <div class="memdoc"> <p>Definition at line <a class="el" href="_c_generic_memory_pool_8h_source.html#l00070">70</a> of file <a class="el" href="_c_generic_memory_pool_8h_source.html">CGenericMemoryPool.h</a>.</p> <p>References <a class="el" href="_c_generic_memory_pool_8h_source.html#l00062">m_maxPoolEntries</a>.</p> </div> </div> <hr/><h2>Member Data Documentation</h2> <a class="anchor" id="a2e0c767b602037d42612b835db6253fd"></a><!-- doxytag: member="mrpt::system::CGenericMemoryPool::m_maxPoolEntries" ref="a2e0c767b602037d42612b835db6253fd" args="" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">size_t <a class="el" href="classmrpt_1_1system_1_1_c_generic_memory_pool.html#a2e0c767b602037d42612b835db6253fd">mrpt::system::CGenericMemoryPool::m_maxPoolEntries</a><code> [private]</code></td> </tr> </table> </div> <div class="memdoc"> <p>Definition at line <a class="el" href="_c_generic_memory_pool_8h_source.html#l00062">62</a> of file <a class="el" href="_c_generic_memory_pool_8h_source.html">CGenericMemoryPool.h</a>.</p> <p>Referenced by <a class="el" href="_c_generic_memory_pool_8h_source.html#l00069">getMemoryPoolMaxSize()</a>, <a class="el" href="_c_generic_memory_pool_8h_source.html#l00070">setMemoryPoolMaxSize()</a>, and <a class="el" href="_c_generic_memory_pool_8h_source.html#l00105">dump_to_pool()</a>.</p> </div> </div> <a class="anchor" id="a348858ea7cc83f0413f33aed477f4453"></a><!-- doxytag: member="mrpt::system::CGenericMemoryPool::m_pool" ref="a348858ea7cc83f0413f33aed477f4453" args="" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname"><a class="el" href="classmrpt_1_1system_1_1_c_generic_memory_pool.html#af7eab650913d4bc790385cb41640f632">TList</a> <a class="el" href="classmrpt_1_1system_1_1_c_generic_memory_pool.html#a348858ea7cc83f0413f33aed477f4453">mrpt::system::CGenericMemoryPool::m_pool</a><code> [private]</code></td> </tr> </table> </div> <div class="memdoc"> <p>Definition at line <a class="el" href="_c_generic_memory_pool_8h_source.html#l00060">60</a> of file <a class="el" href="_c_generic_memory_pool_8h_source.html">CGenericMemoryPool.h</a>.</p> <p>Referenced by <a class="el" href="_c_generic_memory_pool_8h_source.html#l00084">request_memory()</a>, <a class="el" href="_c_generic_memory_pool_8h_source.html#l00105">dump_to_pool()</a>, and <a class="el" href="_c_generic_memory_pool_8h_source.html#l00115">~CGenericMemoryPool()</a>.</p> </div> </div> <a class="anchor" id="a7927dc67b0bf6a1cab0f6aa26fd40f63"></a><!-- doxytag: member="mrpt::system::CGenericMemoryPool::m_pool_cs" ref="a7927dc67b0bf6a1cab0f6aa26fd40f63" args="" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname"><a class="el" href="classmrpt_1_1synch_1_1_c_critical_section.html">mrpt::synch::CCriticalSection</a> <a class="el" href="classmrpt_1_1system_1_1_c_generic_memory_pool.html#a7927dc67b0bf6a1cab0f6aa26fd40f63">mrpt::system::CGenericMemoryPool::m_pool_cs</a><code> [private]</code></td> </tr> </table> </div> <div class="memdoc"> <p>Definition at line <a class="el" href="_c_generic_memory_pool_8h_source.html#l00061">61</a> of file <a class="el" href="_c_generic_memory_pool_8h_source.html">CGenericMemoryPool.h</a>.</p> <p>Referenced by <a class="el" href="_c_generic_memory_pool_8h_source.html#l00084">request_memory()</a>, <a class="el" href="_c_generic_memory_pool_8h_source.html#l00105">dump_to_pool()</a>, and <a class="el" href="_c_generic_memory_pool_8h_source.html#l00115">~CGenericMemoryPool()</a>.</p> </div> </div> </div> <br><hr><br> <table border="0" width="100%"> <tr> <td> Page generated by <a href="http://www.doxygen.org" target="_blank">Doxygen 1.7.5</a> for MRPT 0.9.5 SVN: at Sun Sep 25 17:20:18 UTC 2011</td><td></td> <td width="100"> </td> <td width="150"> </td></tr> </table> </body></html>