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