📄 memory_chunks.sgml
字号:
<row><entry align="right"><parameter>mem_chunk</parameter> :</entry><entry>a <link linkend="GMemChunk">GMemChunk</link>.</entry></row><row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry>a pointer to the allocated atom.</entry></row></tbody></tgroup></informaltable></refsect2><refsect2><title><anchor id="g-mem-chunk-alloc0">g_mem_chunk_alloc0 ()</title><programlisting><link linkend="gpointer">gpointer</link> g_mem_chunk_alloc0 (<link linkend="GMemChunk">GMemChunk</link> *mem_chunk);</programlisting><para>Allocates an atom of memory from a <link linkend="GMemChunk">GMemChunk</link>, setting the memory to 0.</para><informaltable pgwide="1" frame="none" role="params"><tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*"><tbody><row><entry align="right"><parameter>mem_chunk</parameter> :</entry><entry>a <link linkend="GMemChunk">GMemChunk</link>.</entry></row><row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry>a pointer to the allocated atom.</entry></row></tbody></tgroup></informaltable></refsect2><refsect2><title><anchor id="g-mem-chunk-free">g_mem_chunk_free ()</title><programlisting>void g_mem_chunk_free (<link linkend="GMemChunk">GMemChunk</link> *mem_chunk, <link linkend="gpointer">gpointer</link> mem);</programlisting><para>Frees an atom in a <link linkend="GMemChunk">GMemChunk</link>.This should only be called if the <link linkend="GMemChunk">GMemChunk</link> was created with<link linkend="G-ALLOC-AND-FREE-CAPS">G_ALLOC_AND_FREE</link>. Otherwise it will simply return.</para><informaltable pgwide="1" frame="none" role="params"><tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*"><tbody><row><entry align="right"><parameter>mem_chunk</parameter> :</entry><entry>a <link linkend="GMemChunk">GMemChunk</link>.</entry></row><row><entry align="right"><parameter>mem</parameter> :</entry><entry>a pointer to the atom to free.</entry></row></tbody></tgroup></informaltable></refsect2><refsect2><title><anchor id="g-mem-chunk-destroy">g_mem_chunk_destroy ()</title><programlisting>void g_mem_chunk_destroy (<link linkend="GMemChunk">GMemChunk</link> *mem_chunk);</programlisting><para>Frees all of the memory allocated for a <link linkend="GMemChunk">GMemChunk</link>.</para><informaltable pgwide="1" frame="none" role="params"><tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*"><tbody><row><entry align="right"><parameter>mem_chunk</parameter> :</entry><entry>a <link linkend="GMemChunk">GMemChunk</link>.</entry></row></tbody></tgroup></informaltable></refsect2><refsect2><title><anchor id="g-mem-chunk-create">g_mem_chunk_create()</title><programlisting>#define g_mem_chunk_create(type, pre_alloc, alloc_type)</programlisting><para>A convenience macro for creating a new <link linkend="GMemChunk">GMemChunk</link>.It calls <link linkend="g-mem-chunk-new">g_mem_chunk_new</link>(), using the given type to create the <link linkend="GMemChunk">GMemChunk</link>name. The atom size is determined using <function><link linkend="sizeof">sizeof</link>()</function>, and thearea size is calculated by multiplying the <parameter>pre_alloc</parameter> parameter withthe atom size.</para><informaltable pgwide="1" frame="none" role="params"><tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*"><tbody><row><entry align="right"><parameter>type</parameter> :</entry><entry>the type of the atoms, typically a structure name.</entry></row><row><entry align="right"><parameter>pre_alloc</parameter> :</entry><entry>the number of atoms to store in each block of memory.</entry></row><row><entry align="right"><parameter>alloc_type</parameter> :</entry><entry>the type of the <link linkend="GMemChunk">GMemChunk</link>.<link linkend="G-ALLOC-AND-FREE-CAPS">G_ALLOC_AND_FREE</link> is used if the atoms will be freed individually.<link linkend="G-ALLOC-ONLY-CAPS">G_ALLOC_ONLY</link> should be used if atoms will never be freed individually.<link linkend="G-ALLOC-ONLY-CAPS">G_ALLOC_ONLY</link> is quicker, since it does not need to track free atoms,but it obviously wastes memory if you no longer need many of the atoms.</entry></row><row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry>the new <link linkend="GMemChunk">GMemChunk</link>.</entry></row></tbody></tgroup></informaltable></refsect2><refsect2><title><anchor id="g-chunk-new">g_chunk_new()</title><programlisting>#define g_chunk_new(type, chunk)</programlisting><para>A convenience macro to allocate an atom of memory from a <link linkend="GMemChunk">GMemChunk</link>.It calls <link linkend="g-mem-chunk-alloc">g_mem_chunk_alloc</link>() and casts the returned atom to a pointer tothe given type, avoiding a type cast in the source code.</para><informaltable pgwide="1" frame="none" role="params"><tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*"><tbody><row><entry align="right"><parameter>type</parameter> :</entry><entry>the type of the <link linkend="GMemChunk">GMemChunk</link> atoms, typically a structure name.</entry></row><row><entry align="right"><parameter>chunk</parameter> :</entry><entry>a <link linkend="GMemChunk">GMemChunk</link>.</entry></row><row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry>a pointer to the allocated atom, cast to a pointer to <parameter>type</parameter>.</entry></row></tbody></tgroup></informaltable></refsect2><refsect2><title><anchor id="g-chunk-new0">g_chunk_new0()</title><programlisting>#define g_chunk_new0(type, chunk)</programlisting><para>A convenience macro to allocate an atom of memory from a <link linkend="GMemChunk">GMemChunk</link>.It calls <link linkend="g-mem-chunk-alloc0">g_mem_chunk_alloc0</link>() and casts the returned atom to a pointer tothe given type, avoiding a type cast in the source code.</para><informaltable pgwide="1" frame="none" role="params"><tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*"><tbody><row><entry align="right"><parameter>type</parameter> :</entry><entry>the type of the <link linkend="GMemChunk">GMemChunk</link> atoms, typically a structure name.</entry></row><row><entry align="right"><parameter>chunk</parameter> :</entry><entry>a <link linkend="GMemChunk">GMemChunk</link>.</entry></row><row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry>a pointer to the allocated atom, cast to a pointer to <parameter>type</parameter>.</entry></row></tbody></tgroup></informaltable></refsect2><refsect2><title><anchor id="g-chunk-free">g_chunk_free()</title><programlisting>#define g_chunk_free(mem, mem_chunk)</programlisting><para>A convenience macro to free an atom of memory from a <link linkend="GMemChunk">GMemChunk</link>.It simply switches the arguments and calls <link linkend="g-mem-chunk-free">g_mem_chunk_free</link>()It is included simply to complement the other convenience macros, <link linkend="g-chunk-new">g_chunk_new</link>()and <link linkend="g-chunk-new0">g_chunk_new0</link>().</para><informaltable pgwide="1" frame="none" role="params"><tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*"><tbody><row><entry align="right"><parameter>mem</parameter> :</entry><entry>a pointer to the atom to be freed.</entry></row><row><entry align="right"><parameter>mem_chunk</parameter> :</entry><entry>a <link linkend="GMemChunk">GMemChunk</link>.</entry></row></tbody></tgroup></informaltable></refsect2><refsect2><title><anchor id="g-mem-chunk-reset">g_mem_chunk_reset ()</title><programlisting>void g_mem_chunk_reset (<link linkend="GMemChunk">GMemChunk</link> *mem_chunk);</programlisting><para>Resets a GMemChunk to its initial state.It frees all of the currently allocated blocks of memory.</para><informaltable pgwide="1" frame="none" role="params"><tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*"><tbody><row><entry align="right"><parameter>mem_chunk</parameter> :</entry><entry>a <link linkend="GMemChunk">GMemChunk</link>.</entry></row></tbody></tgroup></informaltable></refsect2><refsect2><title><anchor id="g-mem-chunk-clean">g_mem_chunk_clean ()</title><programlisting>void g_mem_chunk_clean (<link linkend="GMemChunk">GMemChunk</link> *mem_chunk);</programlisting><para>Frees any blocks in a <link linkend="GMemChunk">GMemChunk</link> which are no longer being used.</para><informaltable pgwide="1" frame="none" role="params"><tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*"><tbody><row><entry align="right"><parameter>mem_chunk</parameter> :</entry><entry>a <link linkend="GMemChunk">GMemChunk</link>.</entry></row></tbody></tgroup></informaltable></refsect2><refsect2><title><anchor id="g-blow-chunks">g_blow_chunks ()</title><programlisting>void g_blow_chunks (void);</programlisting><para>Calls <link linkend="g-mem-chunk-clean">g_mem_chunk_clean</link>() on all <link linkend="GMemChunk">GMemChunk</link> objects.</para></refsect2><refsect2><title><anchor id="g-mem-chunk-info">g_mem_chunk_info ()</title><programlisting>void g_mem_chunk_info (void);</programlisting><para>Outputs debugging information for all <link linkend="GMemChunk">GMemChunk</link> objects currently in use.It outputs the number of <link linkend="GMemChunk">GMemChunk</link> objects currently allocated,and calls <link linkend="g-mem-chunk-print">g_mem_chunk_print</link>() to output information on each one.</para></refsect2><refsect2><title><anchor id="g-mem-chunk-print">g_mem_chunk_print ()</title><programlisting>void g_mem_chunk_print (<link linkend="GMemChunk">GMemChunk</link> *mem_chunk);</programlisting><para>Outputs debugging information for a <link linkend="GMemChunk">GMemChunk</link>.It outputs the name of the <link linkend="GMemChunk">GMemChunk</link> (set with <link linkend="g-mem-chunk-new">g_mem_chunk_new</link>()),the number of bytes used, and the number of blocks of memory allocated.</para><informaltable pgwide="1" frame="none" role="params"><tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*"><tbody><row><entry align="right"><parameter>mem_chunk</parameter> :</entry><entry>a <link linkend="GMemChunk">GMemChunk</link>.</entry></row></tbody></tgroup></informaltable></refsect2></refsect1></refentry>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -