📄 glib-memory-slices.html
字号:
and the <em class="parameter"><code>block_size</code></em> has to match the size specified upon allocation.Note that the exact release behaviour can be changed with the<a class="link" href="glib-running.html#G_DEBUG" title="G_DEBUG">G_DEBUG=gc-friendly</a> environment variable,also see <a class="link" href="glib-running.html#G_SLICE" title="G_SLICE">G_SLICE</a> for related debugging options.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>block_size</code></em> :</span></p></td><td>the size of the block</td></tr><tr><td><p><span class="term"><em class="parameter"><code>mem_block</code></em> :</span></p></td><td>a pointer to the block to free</td></tr></tbody></table></div><p class="since">Since 2.10</p></div><hr><div class="refsect2" lang="en"><a name="id3230130"></a><h3><a name="g-slice-free-chain-with-offset"></a>g_slice_free_chain_with_offset ()</h3><a class="indexterm" name="id3230146"></a><pre class="programlisting">void g_slice_free_chain_with_offset (<a class="link" href="glib-Basic-Types.html#gsize">gsize</a> block_size, <a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> mem_chain, <a class="link" href="glib-Basic-Types.html#gsize">gsize</a> next_offset);</pre><p>Frees a linked list of memory blocks of structure type <em class="parameter"><code>type</code></em>.The memory blocks must be equal-sized, allocated via<a class="link" href="glib-Memory-Slices.html#g-slice-alloc"><code class="function">g_slice_alloc()</code></a> or <a class="link" href="glib-Memory-Slices.html#g-slice-alloc0"><code class="function">g_slice_alloc0()</code></a>and linked together by a <em class="parameter"><code>next</code></em> pointer (similar to <a class="link" href="glib-Singly-Linked-Lists.html#GSList"><span class="type">GSList</span></a>). The offset of the <em class="parameter"><code>next</code></em> field in each block is passed as third argument.Note that the exact release behaviour can be changed with the<a class="link" href="glib-running.html#G_DEBUG" title="G_DEBUG">G_DEBUG=gc-friendly</a> environment variable,also see <a class="link" href="glib-running.html#G_SLICE" title="G_SLICE">G_SLICE</a> for related debugging options.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>block_size</code></em> :</span></p></td><td>the size of the blocks</td></tr><tr><td><p><span class="term"><em class="parameter"><code>mem_chain</code></em> :</span></p></td><td> a pointer to the first block of the chain</td></tr><tr><td><p><span class="term"><em class="parameter"><code>next_offset</code></em> :</span></p></td><td>the offset of the <em class="parameter"><code>next</code></em> field in the blocks</td></tr></tbody></table></div><p class="since">Since 2.10</p></div><hr><div class="refsect2" lang="en"><a name="id3230317"></a><h3><a name="g-slice-new"></a>g_slice_new()</h3><a class="indexterm" name="id3230332"></a><pre class="programlisting">#define g_slice_new(type)</pre><p>A convenience macro to allocate a block of memory from the slice allocator.It calls <a class="link" href="glib-Memory-Slices.html#g-slice-alloc"><code class="function">g_slice_alloc()</code></a> with <code class="literal">sizeof (<em class="parameter"><code>type</code></em>)</code> and casts the returned pointer to a pointer of the given type, avoiding a type cast in the source code.Note that the underlying slice allocation mechanism canbe changed with the <a class="link" href="glib-running.html#G_SLICE" title="G_SLICE">G_SLICE=always-malloc</a>environment variable.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>type</code></em> :</span></p></td><td>the type to allocate, typically a structure name</td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td><td>a pointer to the allocated block, cast to a pointer to <em class="parameter"><code>type</code></em>.</td></tr></tbody></table></div><p class="since">Since 2.10</p></div><hr><div class="refsect2" lang="en"><a name="id3230424"></a><h3><a name="g-slice-new0"></a>g_slice_new0()</h3><a class="indexterm" name="id3230440"></a><pre class="programlisting">#define g_slice_new0(type)</pre><p>A convenience macro to allocate a block of memory from the slice allocatorand set the memory to 0. It calls <a class="link" href="glib-Memory-Slices.html#g-slice-alloc0"><code class="function">g_slice_alloc0()</code></a> with <code class="literal">sizeof (<em class="parameter"><code>type</code></em>)</code> and casts the returned pointer to a pointer of the given type, avoiding a type cast in the source code.Note that the underlying slice allocation mechanism canbe changed with the <a class="link" href="glib-running.html#G_SLICE" title="G_SLICE">G_SLICE=always-malloc</a>environment variable.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>type</code></em> :</span></p></td><td>the type to allocate, typically a structure name</td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td><td>a pointer to the allocated block, cast to a pointer to <em class="parameter"><code>type</code></em>.</td></tr></tbody></table></div><p class="since">Since 2.10</p></div><hr><div class="refsect2" lang="en"><a name="id3230533"></a><h3><a name="g-slice-dup"></a>g_slice_dup()</h3><a class="indexterm" name="id3230547"></a><pre class="programlisting">#define g_slice_dup(type, mem)</pre><p>A convenience macro to duplicate a block of memory using the slice allocator.It calls <a class="link" href="glib-Memory-Slices.html#g-slice-copy"><code class="function">g_slice_copy()</code></a> with <code class="literal">sizeof (<em class="parameter"><code>type</code></em>)</code> and casts the returned pointer to a pointer of the given type, avoiding a type cast in the source code.Note that the underlying slice allocation mechanism canbe changed with the <a class="link" href="glib-running.html#G_SLICE" title="G_SLICE">G_SLICE=always-malloc</a>environment variable.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>type</code></em> :</span></p></td><td>the type to duplicate, typically a structure name</td></tr><tr><td><p><span class="term"><em class="parameter"><code>mem</code></em> :</span></p></td><td>the memory to copy into the allocated block</td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td><td>a pointer to the allocated block, cast to a pointer to <em class="parameter"><code>type</code></em>.</td></tr></tbody></table></div><p class="since">Since 2.14</p></div><hr><div class="refsect2" lang="en"><a name="id3230654"></a><h3><a name="g-slice-free"></a>g_slice_free()</h3><a class="indexterm" name="id3230669"></a><pre class="programlisting">#define g_slice_free(type, mem)</pre><p>A convenience macro to free a block of memory that has been allocatedfrom the slice allocator. It calls <a class="link" href="glib-Memory-Slices.html#g-slice-free1"><code class="function">g_slice_free1()</code></a> using <code class="literal">sizeof (type)</code> as the block size.Note that the exact release behaviour can be changed with the<a class="link" href="glib-running.html#G_DEBUG" title="G_DEBUG">G_DEBUG=gc-friendly</a> environment variable,also see <a class="link" href="glib-running.html#G_SLICE" title="G_SLICE">G_SLICE</a> for related debugging options.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>type</code></em> :</span></p></td><td>the type of the block to free, typically a structure name</td></tr><tr><td><p><span class="term"><em class="parameter"><code>mem</code></em> :</span></p></td><td>a pointer to the block to free</td></tr></tbody></table></div><p class="since">Since 2.10</p></div><hr><div class="refsect2" lang="en"><a name="id3230759"></a><h3><a name="g-slice-free-chain"></a>g_slice_free_chain()</h3><a class="indexterm" name="id3230774"></a><pre class="programlisting">#define g_slice_free_chain(type, mem_chain, next)</pre><p>Frees a linked list of memory blocks of structure type <em class="parameter"><code>type</code></em>.The memory blocks must be equal-sized, allocated via<a class="link" href="glib-Memory-Slices.html#g-slice-alloc"><code class="function">g_slice_alloc()</code></a> or <a class="link" href="glib-Memory-Slices.html#g-slice-alloc0"><code class="function">g_slice_alloc0()</code></a> and linked together by a <em class="parameter"><code>next</code></em> pointer (similar to <a class="link" href="glib-Singly-Linked-Lists.html#GSList"><span class="type">GSList</span></a>). The name of the<em class="parameter"><code>next</code></em> field in <em class="parameter"><code>type</code></em> is passed as third argument.Note that the exact release behaviour can be changed with the<a class="link" href="glib-running.html#G_DEBUG" title="G_DEBUG">G_DEBUG=gc-friendly</a> environment variable,also see <a class="link" href="glib-running.html#G_SLICE" title="G_SLICE">G_SLICE</a> for related debugging options.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>type</code></em> :</span></p></td><td> the type of the <em class="parameter"><code>mem_chain</code></em> blocks</td></tr><tr><td><p><span class="term"><em class="parameter"><code>mem_chain</code></em> :</span></p></td><td> a pointer to the first block of the chain</td></tr><tr><td><p><span class="term"><em class="parameter"><code>next</code></em> :</span></p></td><td> the field name of the next pointer in <em class="parameter"><code>type</code></em></td></tr></tbody></table></div><p class="since">Since 2.10</p></div></div><div class="refsect1" lang="en"><a name="id3230929"></a><div class="refsect2" lang="en"><a name="id3230930"></a></div><hr><div class="refsect2" lang="en"><a name="id3230931"></a></div></div><div class="footnotes"><br><hr width="100" align="left"><div class="footnote"><p><sup>[<a name="ftn.id3229491" href="#id3229491" class="para">6</a>] </sup><a class="ulink" href="http://citeseer.ist.psu.edu/bonwick94slab.html" target="_top">[Bonwick94]</a> Jeff Bonwick, The slab allocator: An object-caching kernelmemory allocator. USENIX 1994, and <a class="ulink" href="http://citeseer.ist.psu.edu/bonwick01magazines.html" target="_top">[Bonwick01]</a> Bonwick and Jonathan Adams, Magazines and vmem: Extending theslab allocator to many cpu's and arbitrary resources. USENIX 2001</p></div></div></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -