+Wed Dec 27 15:56:53 2006 Tim Janik <timj@gtk.org>
+
+ * glib/tmpl/memory_slices.sgml:
+ * glib/running.sgml: document G_SLICE=debug-blocks.
+
2006-12-27 Matthias Clasen <mclasen@redhat.com>
* glib/running.sgml:
<formalpara id="G_SLICE">
<title><envar>G_SLICE</envar></title>
<para>
- This environment variable allows reconfiguration of the #GSlice
+ This environment variable allows reconfiguration of the GSlice
memory allocator.
<variablelist>
<varlistentry>
released by g_slice_free1() to be actually allocated via direct
calls to g_malloc() and g_free().
This is most useful for memory checkers and similar programs that
- use bohem GC alike algorithms to produce more accurate results.
+ use Bohem GC alike algorithms to produce more accurate results.
It can also be in conjunction with debugging features of the system's
malloc implementation such as glibc's MALLOC_CHECK_=2 to debug
- erroneous slice allocation code.
+ erroneous slice allocation code, allthough <term>debug-blocks</term>
+ usually is a better suited debugging tool.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>debug-blocks</term>
+ <listitem>
+ <para>
+ Using this option (present since GLib-2.13) engages extra code
+ which performs sanity checks on the released memory slices.
+ Invalid slice adresses or slice sizes will be reported and lead to
+ a program halt.
+ This option should only be used in debugging scenarios, because it
+ significantly degrades GSlice performance. Extra per slice memory
+ is requied to do the necessary bookeeping, and multi-thread scalability
+ is given up to perform global slice validation.
+ This option is mostly useful in scenarios where program crashes are encountered
+ while GSlice is in use, but crashes cannot be reproduced with G_SLICE=always-malloc.
+ A potential cause for such a situation that will be caught by G_SLICE=debug-blocks
+ is e.g.:
+ <programlisting>
+ void *slist = g_slist_alloc(); // void* gives up type-safety
+ g_list_free (slist); // corruption: sizeof (GSList) != sizeof (GList)
+ </programlisting>
</para>
</listitem>
</varlistentry>
g_slice_alloc() or g_slice_alloc0()
and the @block_size has to match the size specified upon allocation.
Note that the exact release behaviour can be changed with the
-<link linkend="G_DEBUG">G_DEBUG=gc-friendly</link> environment variable.
+<link linkend="G_DEBUG">G_DEBUG=gc-friendly</link> environment variable,
+also see <link linkend="G_SLICE">G_SLICE</link> for related debugging options.
</para>
@block_size: the size of the block
and linked together by a @next pointer (similar to #GSList). The offset
of the @next field in each block is passed as third argument.
Note that the exact release behaviour can be changed with the
-<link linkend="G_DEBUG">G_DEBUG=gc-friendly</link> environment variable.
+<link linkend="G_DEBUG">G_DEBUG=gc-friendly</link> environment variable,
+also see <link linkend="G_SLICE">G_SLICE</link> for related debugging options.
</para>
@block_size: the size of the blocks
from the slice allocator. It calls g_slice_free1() using
<literal>sizeof (type)</literal> as the block size.
Note that the exact release behaviour can be changed with the
-<link linkend="G_DEBUG">G_DEBUG=gc-friendly</link> environment variable.
+<link linkend="G_DEBUG">G_DEBUG=gc-friendly</link> environment variable,
+also see <link linkend="G_SLICE">G_SLICE</link> for related debugging options.
</para>
@type: the type of the block to free, typically a structure name
@next pointer (similar to #GSList). The name of the
@next field in @type is passed as third argument.
Note that the exact release behaviour can be changed with the
-<link linkend="G_DEBUG">G_DEBUG=gc-friendly</link> environment variable.
+<link linkend="G_DEBUG">G_DEBUG=gc-friendly</link> environment variable,
+also see <link linkend="G_SLICE">G_SLICE</link> for related debugging options.
</para>
@type: the type of the @mem_chain blocks