<!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>Apache Portable Runtime: apr_allocator.h Source File</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> </head><body> <!-- Generated by Doxygen 1.3.9.1 --> <div class="qindex"><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="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related Pages</a></div> <div class="nav"> <a class="el" href="dir_000000.html">home</a> / <a class="el" href="dir_000001.html">oden</a> / <a class="el" href="dir_000002.html">RPM</a> / <a class="el" href="dir_000003.html">BUILD</a> / <a class="el" href="dir_000004.html">apr-1.1.1</a> / <a class="el" href="dir_000005.html">include</a></div> <h1>apr_allocator.h</h1><a href="apr__allocator_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/* Copyright 2000-2004 The Apache Software Foundation</span> 00002 <span class="comment"> *</span> 00003 <span class="comment"> * Licensed under the Apache License, Version 2.0 (the "License");</span> 00004 <span class="comment"> * you may not use this file except in compliance with the License.</span> 00005 <span class="comment"> * You may obtain a copy of the License at</span> 00006 <span class="comment"> *</span> 00007 <span class="comment"> * http://www.apache.org/licenses/LICENSE-2.0</span> 00008 <span class="comment"> *</span> 00009 <span class="comment"> * Unless required by applicable law or agreed to in writing, software</span> 00010 <span class="comment"> * distributed under the License is distributed on an "AS IS" BASIS,</span> 00011 <span class="comment"> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span> 00012 <span class="comment"> * See the License for the specific language governing permissions and</span> 00013 <span class="comment"> * limitations under the License.</span> 00014 <span class="comment"> */</span> 00015 00016 <span class="preprocessor">#ifndef APR_ALLOCATOR_H</span> 00017 <span class="preprocessor"></span><span class="preprocessor">#define APR_ALLOCATOR_H</span> 00018 <span class="preprocessor"></span><span class="comment"></span> 00019 <span class="comment">/**</span> 00020 <span class="comment"> * @file apr_allocator.h</span> 00021 <span class="comment"> * @brief APR Internal Memory Allocation</span> 00022 <span class="comment"> */</span> 00023 00024 <span class="preprocessor">#include "<a class="code" href="apr_8h.html">apr.h</a>"</span> 00025 <span class="preprocessor">#include "<a class="code" href="apr__errno_8h.html">apr_errno.h</a>"</span> <a name="l00026"></a><a class="code" href="apr__allocator_8h.html#a0">00026</a> <span class="preprocessor">#define APR_WANT_MEMFUNC </span><span class="comment">/**< For no good reason? */</span> 00027 <span class="preprocessor">#include "<a class="code" href="apr__want_8h.html">apr_want.h</a>"</span> 00028 00029 <span class="preprocessor">#ifdef __cplusplus</span> 00030 <span class="preprocessor"></span><span class="keyword">extern</span> <span class="stringliteral">"C"</span> { 00031 <span class="preprocessor">#endif</span> 00032 <span class="preprocessor"></span><span class="comment"></span> 00033 <span class="comment">/**</span> 00034 <span class="comment"> * @defgroup apr_allocator Internal Memory Allocation</span> 00035 <span class="comment"> * @ingroup APR </span> 00036 <span class="comment"> * @{</span> 00037 <span class="comment"> */</span> 00038 <span class="comment"></span> 00039 <span class="comment">/** the allocator structure */</span> <a name="l00040"></a><a class="code" href="group__apr__allocator.html#ga0">00040</a> <span class="keyword">typedef</span> <span class="keyword">struct </span><a class="code" href="group__apr__allocator.html#ga0">apr_allocator_t</a> <a class="code" href="group__apr__allocator.html#ga0">apr_allocator_t</a>;<span class="comment"></span> 00041 <span class="comment">/** the structure which holds information about the allocation */</span> <a name="l00042"></a><a class="code" href="group__apr__allocator.html#ga1">00042</a> <span class="keyword">typedef</span> <span class="keyword">struct </span><a class="code" href="structapr__memnode__t.html">apr_memnode_t</a> <a class="code" href="group__apr__allocator.html#ga1">apr_memnode_t</a>; 00043 <span class="comment"></span> 00044 <span class="comment">/** basic memory node structure</span> 00045 <span class="comment"> * @note The next, ref and first_avail fields are available for use by the</span> 00046 <span class="comment"> * caller of apr_allocator_alloc(), the remaining fields are read-only.</span> 00047 <span class="comment"> * The next field has to be used with caution and sensibly set when the</span> 00048 <span class="comment"> * memnode is passed back to apr_allocator_free(). See apr_allocator_free()</span> 00049 <span class="comment"> * for details. </span> 00050 <span class="comment"> * The ref and first_avail fields will be properly restored by</span> 00051 <span class="comment"> * apr_allocator_free().</span> 00052 <span class="comment"> */</span> <a name="l00053"></a><a class="code" href="structapr__memnode__t.html">00053</a> <span class="keyword">struct </span><a class="code" href="group__apr__allocator.html#ga1">apr_memnode_t</a> { <a name="l00054"></a><a class="code" href="structapr__memnode__t.html#o0">00054</a> <a class="code" href="group__apr__allocator.html#ga1">apr_memnode_t</a> *next; <span class="comment">/**< next memnode */</span> <a name="l00055"></a><a class="code" href="structapr__memnode__t.html#o1">00055</a> <a class="code" href="group__apr__allocator.html#ga1">apr_memnode_t</a> **ref; <span class="comment">/**< reference to self */</span> <a name="l00056"></a><a class="code" href="structapr__memnode__t.html#o2">00056</a> apr_uint32_t index; <span class="comment">/**< size */</span> <a name="l00057"></a><a class="code" href="structapr__memnode__t.html#o3">00057</a> apr_uint32_t free_index; <span class="comment">/**< how much free */</span> <a name="l00058"></a><a class="code" href="structapr__memnode__t.html#o4">00058</a> <span class="keywordtype">char</span> *first_avail; <span class="comment">/**< pointer to first free memory */</span> <a name="l00059"></a><a class="code" href="structapr__memnode__t.html#o5">00059</a> <span class="keywordtype">char</span> *endp; <span class="comment">/**< pointer to end of free memory */</span> 00060 }; 00061 <span class="comment"></span> 00062 <span class="comment">/** The base size of a memory node - aligned. */</span> <a name="l00063"></a><a class="code" href="group__apr__allocator.html#ga11">00063</a> <span class="preprocessor">#define APR_MEMNODE_T_SIZE APR_ALIGN_DEFAULT(sizeof(apr_memnode_t))</span> 00064 <span class="preprocessor"></span><span class="comment"></span> 00065 <span class="comment">/** Symbolic constants */</span> <a name="l00066"></a><a class="code" href="group__apr__allocator.html#ga12">00066</a> <span class="preprocessor">#define APR_ALLOCATOR_MAX_FREE_UNLIMITED 0</span> 00067 <span class="preprocessor"></span><span class="comment"></span> 00068 <span class="comment">/**</span> 00069 <span class="comment"> * Create a new allocator</span> 00070 <span class="comment"> * @param allocator The allocator we have just created.</span> 00071 <span class="comment"> *</span> 00072 <span class="comment"> */</span> 00073 <a class="code" href="group__apr__platform.html#ga123">APR_DECLARE</a>(apr_status_t) apr_allocator_create(apr_allocator_t **allocator); 00074 <span class="comment"></span> 00075 <span class="comment">/**</span> 00076 <span class="comment"> * Destroy an allocator</span> 00077 <span class="comment"> * @param allocator The allocator to be destroyed</span> 00078 <span class="comment"> * @remark Any memnodes not given back to the allocator prior to destroying</span> 00079 <span class="comment"> * will _not_ be free()d.</span> 00080 <span class="comment"> */</span> 00081 APR_DECLARE(<span class="keywordtype">void</span>) apr_allocator_destroy(apr_allocator_t *allocator); 00082 <span class="comment"></span> 00083 <span class="comment">/**</span> 00084 <span class="comment"> * Allocate a block of mem from the allocator</span> 00085 <span class="comment"> * @param allocator The allocator to allocate from</span> 00086 <span class="comment"> * @param size The size of the mem to allocate (excluding the</span> 00087 <span class="comment"> * memnode structure)</span> 00088 <span class="comment"> */</span> 00089 APR_DECLARE(apr_memnode_t *) apr_allocator_alloc(apr_allocator_t *allocator, 00090 apr_size_t size); 00091 <span class="comment"></span> 00092 <span class="comment">/**</span> 00093 <span class="comment"> * Free a list of blocks of mem, giving them back to the allocator.</span> 00094 <span class="comment"> * The list is typically terminated by a memnode with its next field</span> 00095 <span class="comment"> * set to NULL.</span> 00096 <span class="comment"> * @param allocator The allocator to give the mem back to</span> 00097 <span class="comment"> * @param memnode The memory node to return</span> 00098 <span class="comment"> */</span> 00099 APR_DECLARE(<span class="keywordtype">void</span>) apr_allocator_free(apr_allocator_t *allocator, 00100 apr_memnode_t *memnode); 00101 00102 #include "apr_pools.h" 00103 <span class="comment"></span> 00104 <span class="comment">/**</span> 00105 <span class="comment"> * Set the owner of the allocator</span> 00106 <span class="comment"> * @param allocator The allocator to set the owner for</span> 00107 <span class="comment"> * @param pool The pool that is to own the allocator</span> 00108 <span class="comment"> * @remark Typically pool is the highest level pool using the allocator</span> 00109 <span class="comment"> */</span> 00110 <span class="comment">/*</span> 00111 <span class="comment"> * XXX: see if we can come up with something a bit better. Currently</span> 00112 <span class="comment"> * you can make a pool an owner, but if the pool doesn't use the allocator</span> 00113 <span class="comment"> * the allocator will never be destroyed.</span> 00114 <span class="comment"> */</span> 00115 APR_DECLARE(<span class="keywordtype">void</span>) apr_allocator_owner_set(apr_allocator_t *allocator, 00116 apr_pool_t *pool); 00117 <span class="comment"></span> 00118 <span class="comment">/**</span> 00119 <span class="comment"> * Get the current owner of the allocator</span> 00120 <span class="comment"> * @param allocator The allocator to get the owner from</span> 00121 <span class="comment"> */</span> 00122 APR_DECLARE(apr_pool_t *) apr_allocator_owner_get(apr_allocator_t *allocator); 00123 <span class="comment"></span> 00124 <span class="comment">/**</span> 00125 <span class="comment"> * Set the current threshold at which the allocator should start</span> 00126 <span class="comment"> * giving blocks back to the system.</span> 00127 <span class="comment"> * @param allocator The allocator the set the threshold on</span> 00128 <span class="comment"> * @param size The threshold. 0 == unlimited.</span> 00129 <span class="comment"> */</span> 00130 APR_DECLARE(<span class="keywordtype">void</span>) apr_allocator_max_free_set(apr_allocator_t *allocator, 00131 apr_size_t size); 00132 00133 #include "apr_thread_mutex.h" 00134 00135 #if APR_HAS_THREADS<span class="comment"></span> 00136 <span class="comment">/**</span> 00137 <span class="comment"> * Set a mutex for the allocator to use</span> 00138 <span class="comment"> * @param allocator The allocator to set the mutex for</span> 00139 <span class="comment"> * @param mutex The mutex</span> 00140 <span class="comment"> */</span> 00141 APR_DECLARE(<span class="keywordtype">void</span>) apr_allocator_mutex_set(apr_allocator_t *allocator, 00142 apr_thread_mutex_t *mutex); 00143 <span class="comment"></span> 00144 <span class="comment">/**</span> 00145 <span class="comment"> * Get the mutex currently set for the allocator</span> 00146 <span class="comment"> * @param allocator The allocator</span> 00147 <span class="comment"> */</span> 00148 APR_DECLARE(apr_thread_mutex_t *) apr_allocator_mutex_get( 00149 apr_allocator_t *allocator); 00150 00151 #endif <span class="comment">/* APR_HAS_THREADS */</span> 00152 <span class="comment"></span> 00153 <span class="comment">/** @} */</span> 00154 00155 #ifdef __cplusplus 00156 } 00157 #endif 00158 00159 #endif <span class="comment">/* !APR_ALLOCATOR_H */</span> </pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Mar 20 19:52:26 2005 for Apache Portable Runtime by <a href="http://www.doxygen.org/index.html"> <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.3.9.1 </small></address> </body> </html>