<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <title>Memory allocation implementation details</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> </head><body> <!-- Generated by Doxygen 1.2.15 --> <center> <a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="modules.html">Modules</a> <a class="qindex" href="annotated.html">Data Structures</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="functions.html">Data Fields</a> <a class="qindex" href="pages.html">Related Pages</a> </center> <hr><h1>Memory allocation implementation details<br> <small> [<a class="el" href="group__DBusInternals.html">D-BUS internal implementation details</a>]</small> </h1>internals of <a class="el" href="group__DBusMemory.html#a0">dbus_malloc</a>() etc. <a href="#_details">More...</a><table border=0 cellpadding=0 cellspacing=0> <tr><td colspan=2><br><h2>Data Structures</h2></td></tr> <tr><td nowrap align=right valign=top>struct </td><td valign=bottom><a class="el" href="structShutdownClosure.html">ShutdownClosure</a></td></tr> <tr><td> </td><td><font size=-1><em>This struct represents a function to be called on shutdown.</em> <a href="structShutdownClosure.html#_details">More...</a><em></em></font><br><br></td></tr> <tr><td colspan=2><br><h2>Defines</h2></td></tr> <tr><td nowrap align=right valign=top><a name="a26" doxytag="DBusMemoryInternals::GUARD_VALUE"></a> #define </td><td valign=bottom><a class="el" href="group__DBusMemoryInternals.html#a26">GUARD_VALUE</a> 0xdeadbeef</td></tr> <tr><td> </td><td><font size=-1><em>value stored in guard padding for debugging buffer overrun.</em></font><br><br></td></tr> <tr><td nowrap align=right valign=top><a name="a27" doxytag="DBusMemoryInternals::GUARD_INFO_SIZE"></a> #define </td><td valign=bottom><a class="el" href="group__DBusMemoryInternals.html#a27">GUARD_INFO_SIZE</a> 8</td></tr> <tr><td> </td><td><font size=-1><em>size of the information about the block stored in guard mode.</em></font><br><br></td></tr> <tr><td nowrap align=right valign=top><a name="a28" doxytag="DBusMemoryInternals::GUARD_START_PAD"></a> #define </td><td valign=bottom><a class="el" href="group__DBusMemoryInternals.html#a28">GUARD_START_PAD</a> 16</td></tr> <tr><td> </td><td><font size=-1><em>size of the GUARD_VALUE-filled padding after the header info.</em></font><br><br></td></tr> <tr><td nowrap align=right valign=top><a name="a29" doxytag="DBusMemoryInternals::GUARD_END_PAD"></a> #define </td><td valign=bottom><a class="el" href="group__DBusMemoryInternals.html#a29">GUARD_END_PAD</a> 16</td></tr> <tr><td> </td><td><font size=-1><em>size of the GUARD_VALUE-filled padding at the end of the block.</em></font><br><br></td></tr> <tr><td nowrap align=right valign=top><a name="a30" doxytag="DBusMemoryInternals::GUARD_START_OFFSET"></a> #define </td><td valign=bottom><a class="el" href="group__DBusMemoryInternals.html#a30">GUARD_START_OFFSET</a> (GUARD_START_PAD + GUARD_INFO_SIZE)</td></tr> <tr><td> </td><td><font size=-1><em>size of stuff at start of block.</em></font><br><br></td></tr> <tr><td nowrap align=right valign=top><a name="a31" doxytag="DBusMemoryInternals::GUARD_EXTRA_SIZE"></a> #define </td><td valign=bottom><a class="el" href="group__DBusMemoryInternals.html#a31">GUARD_EXTRA_SIZE</a> (GUARD_START_OFFSET + GUARD_END_PAD)</td></tr> <tr><td> </td><td><font size=-1><em>total extra size over the requested allocation for guard stuff.</em></font><br><br></td></tr> <tr><td colspan=2><br><h2>Typedefs</h2></td></tr> <tr><td nowrap align=right valign=top><a name="a11" doxytag="DBusMemoryInternals::ShutdownClosure"></a> typedef ShutdownClosure </td><td valign=bottom><a class="el" href="group__DBusMemoryInternals.html#a11">ShutdownClosure</a></td></tr> <tr><td> </td><td><font size=-1><em>Represents a function to be called on shutdown.</em></font><br><br></td></tr> <tr><td colspan=2><br><h2>Enumerations</h2></td></tr> <tr><td nowrap align=right valign=top>enum </td><td valign=bottom><a class="el" href="group__DBusMemoryInternals.html#a32">BlockSource</a> { <br> <b>SOURCE_UNKNOWN</b>, <b>SOURCE_MALLOC</b>, <b>SOURCE_REALLOC</b>, <b>SOURCE_MALLOC_ZERO</b>, <br> <b>SOURCE_REALLOC_NULL</b> <br> }</td></tr> <tr><td> </td><td><font size=-1><em>Where the block came from.</em></font><br><br></td></tr> <tr><td colspan=2><br><h2>Functions</h2></td></tr> <tr><td nowrap align=right valign=top><a class="el" href="group__DBusTypes.html#a2">dbus_bool_t</a> </td><td valign=bottom><a class="el" href="group__DBusMemoryInternals.html#a14">_dbus_disable_mem_pools</a> (void)</td></tr> <tr><td> </td><td><font size=-1><em>Whether to turn off mem pools, useful for leak checking.</em> <a href="#a14">More...</a><em></em></font><br><br></td></tr> <tr><td nowrap align=right valign=top>void </td><td valign=bottom><a class="el" href="group__DBusMemoryInternals.html#a15">_dbus_set_fail_alloc_counter</a> (int until_next_fail)</td></tr> <tr><td> </td><td><font size=-1><em>Sets the number of allocations until we simulate a failed allocation.</em> <a href="#a15">More...</a><em></em></font><br><br></td></tr> <tr><td nowrap align=right valign=top>int </td><td valign=bottom><a class="el" href="group__DBusMemoryInternals.html#a16">_dbus_get_fail_alloc_counter</a> (void)</td></tr> <tr><td> </td><td><font size=-1><em>Gets the number of successful allocs until we'll simulate a failed alloc.</em> <a href="#a16">More...</a><em></em></font><br><br></td></tr> <tr><td nowrap align=right valign=top>void </td><td valign=bottom><a class="el" href="group__DBusMemoryInternals.html#a17">_dbus_set_fail_alloc_failures</a> (int failures_per_failure)</td></tr> <tr><td> </td><td><font size=-1><em>Sets how many mallocs to fail when the fail alloc counter reaches 0.</em> <a href="#a17">More...</a><em></em></font><br><br></td></tr> <tr><td nowrap align=right valign=top>int </td><td valign=bottom><a class="el" href="group__DBusMemoryInternals.html#a18">_dbus_get_fail_alloc_failures</a> (void)</td></tr> <tr><td> </td><td><font size=-1><em>Gets the number of failures we'll have when the fail malloc counter reaches 0.</em> <a href="#a18">More...</a><em></em></font><br><br></td></tr> <tr><td nowrap align=right valign=top><a class="el" href="group__DBusTypes.html#a2">dbus_bool_t</a> </td><td valign=bottom><a class="el" href="group__DBusMemoryInternals.html#a19">_dbus_decrement_fail_alloc_counter</a> (void)</td></tr> <tr><td> </td><td><font size=-1><em>Called when about to alloc some memory; if it returns <a class="el" href="group__DBusMacros.html#a2">TRUE</a>, then the allocation should fail.</em> <a href="#a19">More...</a><em></em></font><br><br></td></tr> <tr><td nowrap align=right valign=top>int </td><td valign=bottom><a class="el" href="group__DBusMemoryInternals.html#a20">_dbus_get_malloc_blocks_outstanding</a> (void)</td></tr> <tr><td> </td><td><font size=-1><em>Get the number of outstanding malloc()'d blocks.</em> <a href="#a20">More...</a><em></em></font><br><br></td></tr> <tr><td nowrap align=right valign=top><a class="el" href="group__DBusTypes.html#a2">dbus_bool_t</a> </td><td valign=bottom><a class="el" href="group__DBusMemoryInternals.html#a24">_dbus_register_shutdown_func</a> (DBusShutdownFunction function, void *data)</td></tr> <tr><td> </td><td><font size=-1><em>Register a cleanup function to be called exactly once the next time <a class="el" href="group__DBusMemory.html#a5">dbus_shutdown</a>() is called.</em> <a href="#a24">More...</a><em></em></font><br><br></td></tr> <tr><td nowrap align=right valign=top><a class="el" href="group__DBusTypes.html#a2">dbus_bool_t</a> </td><td valign=bottom><a class="el" href="group__DBusMemoryInternals.html#a25">_dbus_memory_test</a> (void)</td></tr> <tr><td colspan=2><br><h2>Variables</h2></td></tr> <tr><td nowrap align=right valign=top>int </td><td valign=bottom><a class="el" href="group__DBusMemoryInternals.html#a10">_dbus_current_generation</a> = 1</td></tr> <tr><td> </td><td><font size=-1><em>_dbus_current_generation is used to track each time that <a class="el" href="group__DBusMemory.html#a5">dbus_shutdown</a>() is called, so we can reinit things after it's been called.</em> <a href="#a10">More...</a><em></em></font><br><br></td></tr> </table> <hr><a name="_details"></a><h2>Detailed Description</h2> internals of <a class="el" href="group__DBusMemory.html#a0">dbus_malloc</a>() etc. <p> <p> Implementation details related to allocating and releasing blocks of memory. <hr><h2>Function Documentation</h2> <a name="a19" doxytag="dbus-internals.h::_dbus_decrement_fail_alloc_counter"></a><p> <table width="100%" cellpadding="2" cellspacing="0" border="0"> <tr> <td class="md"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> <a class="el" href="group__DBusTypes.html#a2">dbus_bool_t</a> _dbus_decrement_fail_alloc_counter </td> <td class="md" valign="top">( </td> <td class="md" nowrap valign="top">void </td> <td class="mdname1" valign="top" nowrap> </td> <td class="md" valign="top">) </td> <td class="md" nowrap></td> </tr> </table> </td> </tr> </table> <table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td> <p> Called when about to alloc some memory; if it returns <a class="el" href="group__DBusMacros.html#a2">TRUE</a>, then the allocation should fail. <p> If it returns <a class="el" href="group__DBusMacros.html#a3">FALSE</a>, then the allocation should not fail. <p> <dl compact><dt><b> Returns: </b><dd> <a class="el" href="group__DBusMacros.html#a2">TRUE</a> if this alloc should fail </dl> <p> Definition at line <a class="el" href="dbus-memory_8c-source.html#l00243">243</a> of file <a class="el" href="dbus-memory_8c-source.html">dbus-memory.c</a>. </td> </tr> </table> <a name="a14" doxytag="dbus-internals.h::_dbus_disable_mem_pools"></a><p> <table width="100%" cellpadding="2" cellspacing="0" border="0"> <tr> <td class="md"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> <a class="el" href="group__DBusTypes.html#a2">dbus_bool_t</a> _dbus_disable_mem_pools </td> <td class="md" valign="top">( </td> <td class="md" nowrap valign="top">void </td> <td class="mdname1" valign="top" nowrap> </td> <td class="md" valign="top">) </td> <td class="md" nowrap></td> </tr> </table> </td> </tr> </table> <table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td> <p> Whether to turn off mem pools, useful for leak checking. <p> <dl compact><dt><b> Returns: </b><dd> <a class="el" href="group__DBusMacros.html#a2">TRUE</a> if mempools should not be used. </dl> <p> Definition at line <a class="el" href="dbus-memory_8c-source.html#l00170">170</a> of file <a class="el" href="dbus-memory_8c-source.html">dbus-memory.c</a>. </td> </tr> </table> <a name="a16" doxytag="dbus-internals.h::_dbus_get_fail_alloc_counter"></a><p> <table width="100%" cellpadding="2" cellspacing="0" border="0"> <tr> <td class="md"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> int _dbus_get_fail_alloc_counter </td> <td class="md" valign="top">( </td> <td class="md" nowrap valign="top">void </td> <td class="mdname1" valign="top" nowrap> </td> <td class="md" valign="top">) </td> <td class="md" nowrap></td> </tr> </table> </td> </tr> </table> <table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td> <p> Gets the number of successful allocs until we'll simulate a failed alloc. <p> <dl compact><dt><b> Returns: </b><dd> current counter value </dl> <p> Definition at line <a class="el" href="dbus-memory_8c-source.html#l00203">203</a> of file <a class="el" href="dbus-memory_8c-source.html">dbus-memory.c</a>. </td> </tr> </table> <a name="a18" doxytag="dbus-internals.h::_dbus_get_fail_alloc_failures"></a><p> <table width="100%" cellpadding="2" cellspacing="0" border="0"> <tr> <td class="md"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> int _dbus_get_fail_alloc_failures </td> <td class="md" valign="top">( </td> <td class="md" nowrap valign="top">void </td> <td class="mdname1" valign="top" nowrap> </td> <td class="md" valign="top">) </td> <td class="md" nowrap></td> </tr> </table> </td> </tr> </table> <table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td> <p> Gets the number of failures we'll have when the fail malloc counter reaches 0. <p> <dl compact><dt><b> Returns: </b><dd> number of failures planned </dl> <p> Definition at line <a class="el" href="dbus-memory_8c-source.html#l00229">229</a> of file <a class="el" href="dbus-memory_8c-source.html">dbus-memory.c</a>. </td> </tr> </table> <a name="a20" doxytag="dbus-internals.h::_dbus_get_malloc_blocks_outstanding"></a><p> <table width="100%" cellpadding="2" cellspacing="0" border="0"> <tr> <td class="md"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> int _dbus_get_malloc_blocks_outstanding </td> <td class="md" valign="top">( </td> <td class="md" nowrap valign="top">void </td> <td class="mdname1" valign="top" nowrap> </td> <td class="md" valign="top">) </td> <td class="md" nowrap></td> </tr> </table> </td> </tr> </table> <table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td> <p> Get the number of outstanding malloc()'d blocks. <p> <dl compact><dt><b> Returns: </b><dd> number of blocks </dl> <p> Definition at line <a class="el" href="dbus-memory_8c-source.html#l00282">282</a> of file <a class="el" href="dbus-memory_8c-source.html">dbus-memory.c</a>. </td> </tr> </table> <a name="a25" doxytag="dbus-memory.c::_dbus_memory_test"></a><p> <table width="100%" cellpadding="2" cellspacing="0" border="0"> <tr> <td class="md"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> <a class="el" href="group__DBusTypes.html#a2">dbus_bool_t</a> _dbus_memory_test </td> <td class="md" valign="top">( </td> <td class="md" nowrap valign="top">void </td> <td class="mdname1" valign="top" nowrap> </td> <td class="md" valign="top">) </td> <td class="md" nowrap></td> </tr> </table> </td> </tr> </table> <table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td> <p> Unit test for DBusMemory <dl compact><dt><b> Returns: </b><dd> <a class="el" href="group__DBusMacros.html#a2">TRUE</a> on success. </dl> <p> Definition at line <a class="el" href="dbus-memory_8c-source.html#l00777">777</a> of file <a class="el" href="dbus-memory_8c-source.html">dbus-memory.c</a>. </td> </tr> </table> <a name="a24" doxytag="dbus-internals.h::_dbus_register_shutdown_func"></a><p> <table width="100%" cellpadding="2" cellspacing="0" border="0"> <tr> <td class="md"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> <a class="el" href="group__DBusTypes.html#a2">dbus_bool_t</a> _dbus_register_shutdown_func </td> <td class="md" valign="top">( </td> <td class="md" nowrap valign="top">DBusShutdownFunction </td> <td class="mdname" nowrap> <em>func</em>, </td> </tr> <tr> <td></td> <td></td> <td class="md" nowrap>void * </td> <td class="mdname" nowrap> <em>data</em></td> </tr> <tr> <td></td> <td class="md">) </td> <td class="md" colspan="2"></td> </tr> </table> </td> </tr> </table> <table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td> <p> Register a cleanup function to be called exactly once the next time <a class="el" href="group__DBusMemory.html#a5">dbus_shutdown</a>() is called. <p> <dl compact><dt><b> Parameters: </b><dd> <table border=0 cellspacing=2 cellpadding=0> <tr><td valign=top><em>func</em> </td><td> the function </td></tr> <tr><td valign=top><em>data</em> </td><td> data to pass to the function </td></tr> </table> </dl><dl compact><dt><b> Returns: </b><dd> <a class="el" href="group__DBusMacros.html#a3">FALSE</a> on not enough memory </dl> <p> Definition at line <a class="el" href="dbus-memory_8c-source.html#l00704">704</a> of file <a class="el" href="dbus-memory_8c-source.html">dbus-memory.c</a>. <p> References <a class="el" href="dbus-memory_8c-source.html#l00689">ShutdownClosure::data</a>, <a class="el" href="dbus-memory_8c-source.html#l00688">ShutdownClosure::func</a>, and <a class="el" href="dbus-memory_8c-source.html#l00687">ShutdownClosure::next</a>. </td> </tr> </table> <a name="a15" doxytag="dbus-internals.h::_dbus_set_fail_alloc_counter"></a><p> <table width="100%" cellpadding="2" cellspacing="0" border="0"> <tr> <td class="md"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> void _dbus_set_fail_alloc_counter </td> <td class="md" valign="top">( </td> <td class="md" nowrap valign="top">int </td> <td class="mdname1" valign="top" nowrap> <em>until_next_fail</em> </td> <td class="md" valign="top">) </td> <td class="md" nowrap></td> </tr> </table> </td> </tr> </table> <table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td> <p> Sets the number of allocations until we simulate a failed allocation. <p> If set to 0, the next allocation to run fails; if set to 1, one succeeds then the next fails; etc. Set to _DBUS_INT_MAX to not fail anything.<dl compact><dt><b> Parameters: </b><dd> <table border=0 cellspacing=2 cellpadding=0> <tr><td valign=top><em>until_next_fail</em> </td><td> number of successful allocs before one fails </td></tr> </table> </dl> <p> Definition at line <a class="el" href="dbus-memory_8c-source.html#l00185">185</a> of file <a class="el" href="dbus-memory_8c-source.html">dbus-memory.c</a>. </td> </tr> </table> <a name="a17" doxytag="dbus-internals.h::_dbus_set_fail_alloc_failures"></a><p> <table width="100%" cellpadding="2" cellspacing="0" border="0"> <tr> <td class="md"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> void _dbus_set_fail_alloc_failures </td> <td class="md" valign="top">( </td> <td class="md" nowrap valign="top">int </td> <td class="mdname1" valign="top" nowrap> <em>failures_per_failure</em> </td> <td class="md" valign="top">) </td> <td class="md" nowrap></td> </tr> </table> </td> </tr> </table> <table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td> <p> Sets how many mallocs to fail when the fail alloc counter reaches 0. <p> <dl compact><dt><b> Parameters: </b><dd> <table border=0 cellspacing=2 cellpadding=0> <tr><td valign=top><em>failures_per_failure</em> </td><td> number to fail </td></tr> </table> </dl> <p> Definition at line <a class="el" href="dbus-memory_8c-source.html#l00217">217</a> of file <a class="el" href="dbus-memory_8c-source.html">dbus-memory.c</a>. </td> </tr> </table> <hr><h2>Variable Documentation</h2> <a name="a10" doxytag="dbus-memory.c::_dbus_current_generation"></a><p> <table width="100%" cellpadding="2" cellspacing="0" border="0"> <tr> <td class="md"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> int _dbus_current_generation = 1 </table> </td> </tr> </table> <table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td> <p> _dbus_current_generation is used to track each time that <a class="el" href="group__DBusMemory.html#a5">dbus_shutdown</a>() is called, so we can reinit things after it's been called. <p> It is simply incremented each time we shut down. <p> Definition at line <a class="el" href="dbus-memory_8c-source.html#l00675">675</a> of file <a class="el" href="dbus-memory_8c-source.html">dbus-memory.c</a>. </td> </tr> </table> <hr><address align="right"><small>Generated on Wed Jun 9 05:01:28 2004 for D-BUS by <a href="http://www.doxygen.org/index.html"> <img src="doxygen.png" alt="doxygen" align="middle" border=0 width=110 height=53></a>1.2.15 </small></address> </body> </html>