1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <title>Memory Chunks</title>
6 <meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
7 <link rel="home" href="index.html" title="GLib Reference Manual">
8 <link rel="up" href="glib-data-types.html" title="GLib Data Types">
9 <link rel="prev" href="glib-Memory-Slices.html" title="Memory Slices">
10 <link rel="next" href="glib-Doubly-Linked-Lists.html" title="Doubly-Linked Lists">
11 <meta name="generator" content="GTK-Doc V1.13 (XML mode)">
12 <link rel="stylesheet" href="style.css" type="text/css">
13 <link rel="chapter" href="glib.html" title="GLib Overview">
14 <link rel="chapter" href="glib-fundamentals.html" title="GLib Fundamentals">
15 <link rel="chapter" href="glib-core.html" title="GLib Core Application Support">
16 <link rel="chapter" href="glib-utilities.html" title="GLib Utilities">
17 <link rel="chapter" href="glib-data-types.html" title="GLib Data Types">
18 <link rel="chapter" href="tools.html" title="GLib Tools">
19 <link rel="index" href="api-index-full.html" title="Index">
20 <link rel="index" href="api-index-deprecated.html" title="Index of deprecated symbols">
21 <link rel="index" href="api-index-2-2.html" title="Index of new symbols in 2.2">
22 <link rel="index" href="api-index-2-4.html" title="Index of new symbols in 2.4">
23 <link rel="index" href="api-index-2-6.html" title="Index of new symbols in 2.6">
24 <link rel="index" href="api-index-2-8.html" title="Index of new symbols in 2.8">
25 <link rel="index" href="api-index-2-10.html" title="Index of new symbols in 2.10">
26 <link rel="index" href="api-index-2-12.html" title="Index of new symbols in 2.12">
27 <link rel="index" href="api-index-2-14.html" title="Index of new symbols in 2.14">
28 <link rel="index" href="api-index-2-16.html" title="Index of new symbols in 2.16">
29 <link rel="index" href="api-index-2-18.html" title="Index of new symbols in 2.18">
30 <link rel="index" href="api-index-2-20.html" title="Index of new symbols in 2.20">
31 <link rel="index" href="api-index-2-22.html" title="Index of new symbols in 2.22">
32 <link rel="index" href="api-index-2-24.html" title="Index of new symbols in 2.24">
34 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
35 <table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2">
37 <td><a accesskey="p" href="glib-Memory-Slices.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
38 <td><a accesskey="u" href="glib-data-types.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
39 <td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
40 <th width="100%" align="center">GLib Reference Manual</th>
41 <td><a accesskey="n" href="glib-Doubly-Linked-Lists.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
43 <tr><td colspan="5" class="shortcuts">
44 <a href="#glib-Memory-Chunks.synopsis" class="shortcut">Top</a>
46 <a href="#glib-Memory-Chunks.description" class="shortcut">Description</a>
49 <div class="refentry" title="Memory Chunks">
50 <a name="glib-Memory-Chunks"></a><div class="titlepage"></div>
51 <div class="refnamediv"><table width="100%"><tr>
53 <h2><span class="refentrytitle"><a name="glib-Memory-Chunks.top_of_page"></a>Memory Chunks</span></h2>
54 <p>Memory Chunks — deprecated way to allocate groups of equal-sized
57 <td valign="top" align="right"></td>
59 <div class="refsynopsisdiv" title="Synopsis">
60 <a name="glib-Memory-Chunks.synopsis"></a><h2>Synopsis</h2>
61 <pre class="synopsis">
62 #include <glib.h>
64 <a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk">GMemChunk</a>;
65 #define <a class="link" href="glib-Memory-Chunks.html#G-ALLOC-AND-FREE:CAPS" title="G_ALLOC_AND_FREE">G_ALLOC_AND_FREE</a>
66 #define <a class="link" href="glib-Memory-Chunks.html#G-ALLOC-ONLY:CAPS" title="G_ALLOC_ONLY">G_ALLOC_ONLY</a>
68 <a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="returnvalue">GMemChunk</span></a>* <a class="link" href="glib-Memory-Chunks.html#g-mem-chunk-new" title="g_mem_chunk_new ()">g_mem_chunk_new</a> (const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> *name,
69 <a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="returnvalue">gint</span></a> atom_size,
70 <a class="link" href="glib-Basic-Types.html#gsize" title="gsize"><span class="returnvalue">gsize</span></a> area_size,
71 <a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="returnvalue">gint</span></a> type);
72 <a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="returnvalue">gpointer</span></a> <a class="link" href="glib-Memory-Chunks.html#g-mem-chunk-alloc" title="g_mem_chunk_alloc ()">g_mem_chunk_alloc</a> (<a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="returnvalue">GMemChunk</span></a> *mem_chunk);
73 <a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="returnvalue">gpointer</span></a> <a class="link" href="glib-Memory-Chunks.html#g-mem-chunk-alloc0" title="g_mem_chunk_alloc0 ()">g_mem_chunk_alloc0</a> (<a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="returnvalue">GMemChunk</span></a> *mem_chunk);
74 <span class="returnvalue">void</span> <a class="link" href="glib-Memory-Chunks.html#g-mem-chunk-free" title="g_mem_chunk_free ()">g_mem_chunk_free</a> (<a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="returnvalue">GMemChunk</span></a> *mem_chunk,
75 <a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="returnvalue">gpointer</span></a> mem);
76 <span class="returnvalue">void</span> <a class="link" href="glib-Memory-Chunks.html#g-mem-chunk-destroy" title="g_mem_chunk_destroy ()">g_mem_chunk_destroy</a> (<a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="returnvalue">GMemChunk</span></a> *mem_chunk);
78 #define <a class="link" href="glib-Memory-Chunks.html#g-mem-chunk-create" title="g_mem_chunk_create()">g_mem_chunk_create</a> (type, pre_alloc, alloc_type)
79 #define <a class="link" href="glib-Memory-Chunks.html#g-chunk-new" title="g_chunk_new()">g_chunk_new</a> (type, chunk)
80 #define <a class="link" href="glib-Memory-Chunks.html#g-chunk-new0" title="g_chunk_new0()">g_chunk_new0</a> (type, chunk)
81 #define <a class="link" href="glib-Memory-Chunks.html#g-chunk-free" title="g_chunk_free()">g_chunk_free</a> (mem, mem_chunk)
83 <span class="returnvalue">void</span> <a class="link" href="glib-Memory-Chunks.html#g-mem-chunk-reset" title="g_mem_chunk_reset ()">g_mem_chunk_reset</a> (<a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="returnvalue">GMemChunk</span></a> *mem_chunk);
84 <span class="returnvalue">void</span> <a class="link" href="glib-Memory-Chunks.html#g-mem-chunk-clean" title="g_mem_chunk_clean ()">g_mem_chunk_clean</a> (<a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="returnvalue">GMemChunk</span></a> *mem_chunk);
85 <span class="returnvalue">void</span> <a class="link" href="glib-Memory-Chunks.html#g-blow-chunks" title="g_blow_chunks ()">g_blow_chunks</a> (void);
87 <span class="returnvalue">void</span> <a class="link" href="glib-Memory-Chunks.html#g-mem-chunk-info" title="g_mem_chunk_info ()">g_mem_chunk_info</a> (void);
88 <span class="returnvalue">void</span> <a class="link" href="glib-Memory-Chunks.html#g-mem-chunk-print" title="g_mem_chunk_print ()">g_mem_chunk_print</a> (<a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="returnvalue">GMemChunk</span></a> *mem_chunk);
91 <div class="refsect1" title="Description">
92 <a name="glib-Memory-Chunks.description"></a><h2>Description</h2>
94 Memory chunks provide an space-efficient way to allocate equal-sized
95 pieces of memory, called atoms. However, due to the administrative
96 overhead (in particular for <a class="link" href="glib-Memory-Chunks.html#G-ALLOC-AND-FREE:CAPS" title="G_ALLOC_AND_FREE"><span class="type">G_ALLOC_AND_FREE</span></a>, and when used from
97 multiple threads), they are in practise often slower than direct use
98 of <a class="link" href="glib-Memory-Allocation.html#g-malloc" title="g_malloc ()"><code class="function">g_malloc()</code></a>. Therefore, memory chunks have been deprecated in
99 favor of the <a class="link" href="glib-Memory-Slices.html" title="Memory Slices">slice
100 allocator</a>, which has been added in 2.10. All internal uses of
101 memory chunks in GLib have been converted to the
102 <code class="literal">g_slice</code> API.
105 There are two types of memory chunks, <a class="link" href="glib-Memory-Chunks.html#G-ALLOC-ONLY:CAPS" title="G_ALLOC_ONLY"><span class="type">G_ALLOC_ONLY</span></a>, and
106 <a class="link" href="glib-Memory-Chunks.html#G-ALLOC-AND-FREE:CAPS" title="G_ALLOC_AND_FREE"><span class="type">G_ALLOC_AND_FREE</span></a>. </p>
107 <div class="itemizedlist"><ul class="itemizedlist" type="disc">
108 <li class="listitem"><p> <a class="link" href="glib-Memory-Chunks.html#G-ALLOC-ONLY:CAPS" title="G_ALLOC_ONLY"><span class="type">G_ALLOC_ONLY</span></a>
109 chunks only allow allocation of atoms. The atoms can never be freed
110 individually. The memory chunk can only be free in its entirety.
112 <li class="listitem"><p> <a class="link" href="glib-Memory-Chunks.html#G-ALLOC-AND-FREE:CAPS" title="G_ALLOC_AND_FREE"><span class="type">G_ALLOC_AND_FREE</span></a> chunks do
113 allow atoms to be freed individually. The disadvantage of this is
114 that the memory chunk has to keep track of which atoms have been
115 freed. This results in more memory being used and a slight
116 degradation in performance. </p></li>
121 To create a memory chunk use <a class="link" href="glib-Memory-Chunks.html#g-mem-chunk-new" title="g_mem_chunk_new ()"><code class="function">g_mem_chunk_new()</code></a> or the convenience
122 macro <a class="link" href="glib-Memory-Chunks.html#g-mem-chunk-create" title="g_mem_chunk_create()"><code class="function">g_mem_chunk_create()</code></a>.
125 To allocate a new atom use <a class="link" href="glib-Memory-Chunks.html#g-mem-chunk-alloc" title="g_mem_chunk_alloc ()"><code class="function">g_mem_chunk_alloc()</code></a>,
126 <a class="link" href="glib-Memory-Chunks.html#g-mem-chunk-alloc0" title="g_mem_chunk_alloc0 ()"><code class="function">g_mem_chunk_alloc0()</code></a>, or the convenience macros <a class="link" href="glib-Memory-Chunks.html#g-chunk-new" title="g_chunk_new()"><code class="function">g_chunk_new()</code></a> or
127 <a class="link" href="glib-Memory-Chunks.html#g-chunk-new0" title="g_chunk_new0()"><code class="function">g_chunk_new0()</code></a>.
130 To free an atom use <a class="link" href="glib-Memory-Chunks.html#g-mem-chunk-free" title="g_mem_chunk_free ()"><code class="function">g_mem_chunk_free()</code></a>, or the convenience macro
131 <a class="link" href="glib-Memory-Chunks.html#g-chunk-free" title="g_chunk_free()"><code class="function">g_chunk_free()</code></a>. (Atoms can only be freed if the memory chunk is
132 created with the type set to <a class="link" href="glib-Memory-Chunks.html#G-ALLOC-AND-FREE:CAPS" title="G_ALLOC_AND_FREE"><span class="type">G_ALLOC_AND_FREE</span></a>.)
135 To free any blocks of memory which are no longer being used, use
136 <a class="link" href="glib-Memory-Chunks.html#g-mem-chunk-clean" title="g_mem_chunk_clean ()"><code class="function">g_mem_chunk_clean()</code></a>. To clean all memory chunks, use <a class="link" href="glib-Memory-Chunks.html#g-blow-chunks" title="g_blow_chunks ()"><code class="function">g_blow_chunks()</code></a>.
139 To reset the memory chunk, freeing all of the atoms, use
140 <a class="link" href="glib-Memory-Chunks.html#g-mem-chunk-reset" title="g_mem_chunk_reset ()"><code class="function">g_mem_chunk_reset()</code></a>.
143 To destroy a memory chunk, use <a class="link" href="glib-Memory-Chunks.html#g-mem-chunk-destroy" title="g_mem_chunk_destroy ()"><code class="function">g_mem_chunk_destroy()</code></a>.
146 To help debug memory chunks, use <a class="link" href="glib-Memory-Chunks.html#g-mem-chunk-info" title="g_mem_chunk_info ()"><code class="function">g_mem_chunk_info()</code></a> and
147 <a class="link" href="glib-Memory-Chunks.html#g-mem-chunk-print" title="g_mem_chunk_print ()"><code class="function">g_mem_chunk_print()</code></a>.
151 <div class="example">
152 <a name="id594507"></a><p class="title"><b>Example 17. Using a <a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="type">GMemChunk</span></a></b></p>
153 <div class="example-contents"><pre class="programlisting">
154 GMemChunk *mem_chunk;
158 /* Create a GMemChunk with atoms 50 bytes long, and memory
159 blocks holding 100 bytes. Note that this means that only 2 atoms
160 fit into each memory block and so isn't very efficient. */
161 mem_chunk = g_mem_chunk_new ("test mem chunk", 50, 100, G_ALLOC_AND_FREE);
162 /* Now allocate 10000 atoms. */
163 for (i = 0; i < 10000; i++)
165 mem[i] = g_chunk_new (gchar, mem_chunk);
166 /* Fill in the atom memory with some junk. */
167 for (j = 0; j < 50; j++)
170 /* Now free all of the atoms. Note that since we are going to
171 destroy the GMemChunk, this wouldn't normally be used. */
172 for (i = 0; i < 10000; i++)
174 g_mem_chunk_free (mem_chunk, mem[i]);
176 /* We are finished with the GMemChunk, so we destroy it. */
177 g_mem_chunk_destroy (mem_chunk);
180 <p><br class="example-break">
184 <div class="example">
185 <a name="id671836"></a><p class="title"><b>Example 18. Using a <a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="type">GMemChunk</span></a> with data structures</b></p>
186 <div class="example-contents"><pre class="programlisting">
187 GMemChunk *array_mem_chunk;
189 /* Create a GMemChunk to hold GRealArray structures, using
190 the g_mem_chunk_create() convenience macro. We want 1024 atoms in each
191 memory block, and we want to be able to free individual atoms. */
192 array_mem_chunk = g_mem_chunk_create (GRealArray, 1024, G_ALLOC_AND_FREE);
193 /* Allocate one atom, using the g_chunk_new() convenience macro. */
194 array = g_chunk_new (GRealArray, array_mem_chunk);
195 /* We can now use array just like a normal pointer to a structure. */
196 array->data = NULL;
199 array->zero_terminated = (zero_terminated ? 1 : 0);
200 array->clear = (clear ? 1 : 0);
201 array->elt_size = elt_size;
202 /* We can free the element, so it can be reused. */
203 g_chunk_free (array, array_mem_chunk);
204 /* We destroy the GMemChunk when we are finished with it. */
205 g_mem_chunk_destroy (array_mem_chunk);
208 <p><br class="example-break"></p>
210 <div class="refsect1" title="Details">
211 <a name="glib-Memory-Chunks.details"></a><h2>Details</h2>
212 <div class="refsect2" title="GMemChunk">
213 <a name="GMemChunk"></a><h3>GMemChunk</h3>
214 <pre class="programlisting">typedef struct _GMemChunk GMemChunk;</pre>
215 <div class="warning" title="Warning" style="margin-left: 0.5in; margin-right: 0.5in;">
216 <h3 class="title">Warning</h3>
217 <p><code class="literal">GMemChunk</code> is deprecated and should not be used in newly-written code.</p>
220 The <a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="type">GMemChunk</span></a> struct is an opaque data structure representing a
221 memory chunk. It should be accessed only through the use of the
222 following functions.</p>
225 <div class="refsect2" title="G_ALLOC_AND_FREE">
226 <a name="G-ALLOC-AND-FREE:CAPS"></a><h3>G_ALLOC_AND_FREE</h3>
227 <pre class="programlisting">#define G_ALLOC_AND_FREE 2
229 <div class="warning" title="Warning" style="margin-left: 0.5in; margin-right: 0.5in;">
230 <h3 class="title">Warning</h3>
231 <p><code class="literal">G_ALLOC_AND_FREE</code> is deprecated and should not be used in newly-written code.</p>
234 Specifies the type of a <a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="type">GMemChunk</span></a>. Used in <a class="link" href="glib-Memory-Chunks.html#g-mem-chunk-new" title="g_mem_chunk_new ()"><code class="function">g_mem_chunk_new()</code></a> and
235 <a class="link" href="glib-Memory-Chunks.html#g-mem-chunk-create" title="g_mem_chunk_create()"><code class="function">g_mem_chunk_create()</code></a> to specify that atoms will be freed
239 <div class="refsect2" title="G_ALLOC_ONLY">
240 <a name="G-ALLOC-ONLY:CAPS"></a><h3>G_ALLOC_ONLY</h3>
241 <pre class="programlisting">#define G_ALLOC_ONLY 1
243 <div class="warning" title="Warning" style="margin-left: 0.5in; margin-right: 0.5in;">
244 <h3 class="title">Warning</h3>
245 <p><code class="literal">G_ALLOC_ONLY</code> is deprecated and should not be used in newly-written code.</p>
248 Specifies the type of a <a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="type">GMemChunk</span></a>. Used in <a class="link" href="glib-Memory-Chunks.html#g-mem-chunk-new" title="g_mem_chunk_new ()"><code class="function">g_mem_chunk_new()</code></a> and
249 <a class="link" href="glib-Memory-Chunks.html#g-mem-chunk-create" title="g_mem_chunk_create()"><code class="function">g_mem_chunk_create()</code></a> to specify that atoms will never be freed
253 <div class="refsect2" title="g_mem_chunk_new ()">
254 <a name="g-mem-chunk-new"></a><h3>g_mem_chunk_new ()</h3>
255 <pre class="programlisting"><a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="returnvalue">GMemChunk</span></a>* g_mem_chunk_new (const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> *name,
256 <a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="returnvalue">gint</span></a> atom_size,
257 <a class="link" href="glib-Basic-Types.html#gsize" title="gsize"><span class="returnvalue">gsize</span></a> area_size,
258 <a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="returnvalue">gint</span></a> type);</pre>
259 <div class="warning" title="Warning" style="margin-left: 0.5in; margin-right: 0.5in;">
260 <h3 class="title">Warning</h3>
261 <p><code class="literal">g_mem_chunk_new</code> has been deprecated since version 2.10 and should not be used in newly-written code. Use the <a class="link" href="glib-Memory-Slices.html" title="Memory Slices">slice
262 allocator</a> instead</p>
265 Creates a new <a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="type">GMemChunk</span></a>.</p>
266 <div class="variablelist"><table border="0">
267 <col align="left" valign="top">
270 <td><p><span class="term"><em class="parameter"><code>name</code></em> :</span></p></td>
271 <td> a string to identify the <a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="type">GMemChunk</span></a>. It is not copied so it
272 should be valid for the lifetime of the <a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="type">GMemChunk</span></a>. It is
273 only used in <a class="link" href="glib-Memory-Chunks.html#g-mem-chunk-print" title="g_mem_chunk_print ()"><code class="function">g_mem_chunk_print()</code></a>, which is used for debugging.
277 <td><p><span class="term"><em class="parameter"><code>atom_size</code></em> :</span></p></td>
278 <td> the size, in bytes, of each element in the <a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="type">GMemChunk</span></a>.
282 <td><p><span class="term"><em class="parameter"><code>area_size</code></em> :</span></p></td>
283 <td> the size, in bytes, of each block of memory allocated to
288 <td><p><span class="term"><em class="parameter"><code>type</code></em> :</span></p></td>
289 <td> the type of the <a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="type">GMemChunk</span></a>. <a class="link" href="glib-Memory-Chunks.html#G-ALLOC-AND-FREE:CAPS" title="G_ALLOC_AND_FREE"><span class="type">G_ALLOC_AND_FREE</span></a> is used if the
290 atoms will be freed individually. <a class="link" href="glib-Memory-Chunks.html#G-ALLOC-ONLY:CAPS" title="G_ALLOC_ONLY"><span class="type">G_ALLOC_ONLY</span></a> should be
291 used if atoms will never be freed individually.
292 <a class="link" href="glib-Memory-Chunks.html#G-ALLOC-ONLY:CAPS" title="G_ALLOC_ONLY"><span class="type">G_ALLOC_ONLY</span></a> is quicker, since it does not need to track
293 free atoms, but it obviously wastes memory if you no longer
294 need many of the atoms.
298 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
299 <td> the new <a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="type">GMemChunk</span></a>.
306 <div class="refsect2" title="g_mem_chunk_alloc ()">
307 <a name="g-mem-chunk-alloc"></a><h3>g_mem_chunk_alloc ()</h3>
308 <pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="returnvalue">gpointer</span></a> g_mem_chunk_alloc (<a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="returnvalue">GMemChunk</span></a> *mem_chunk);</pre>
309 <div class="warning" title="Warning" style="margin-left: 0.5in; margin-right: 0.5in;">
310 <h3 class="title">Warning</h3>
311 <p><code class="literal">g_mem_chunk_alloc</code> has been deprecated since version 2.10 and should not be used in newly-written code. Use <a class="link" href="glib-Memory-Slices.html#g-slice-alloc" title="g_slice_alloc ()"><code class="function">g_slice_alloc()</code></a> instead</p>
314 Allocates an atom of memory from a <a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="type">GMemChunk</span></a>.</p>
315 <div class="variablelist"><table border="0">
316 <col align="left" valign="top">
319 <td><p><span class="term"><em class="parameter"><code>mem_chunk</code></em> :</span></p></td>
320 <td> a <a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="type">GMemChunk</span></a>.
324 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
325 <td> a pointer to the allocated atom.
332 <div class="refsect2" title="g_mem_chunk_alloc0 ()">
333 <a name="g-mem-chunk-alloc0"></a><h3>g_mem_chunk_alloc0 ()</h3>
334 <pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="returnvalue">gpointer</span></a> g_mem_chunk_alloc0 (<a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="returnvalue">GMemChunk</span></a> *mem_chunk);</pre>
335 <div class="warning" title="Warning" style="margin-left: 0.5in; margin-right: 0.5in;">
336 <h3 class="title">Warning</h3>
337 <p><code class="literal">g_mem_chunk_alloc0</code> has been deprecated since version 2.10 and should not be used in newly-written code. Use <a class="link" href="glib-Memory-Slices.html#g-slice-alloc0" title="g_slice_alloc0 ()"><code class="function">g_slice_alloc0()</code></a> instead</p>
340 Allocates an atom of memory from a <a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="type">GMemChunk</span></a>, setting the memory to
342 <div class="variablelist"><table border="0">
343 <col align="left" valign="top">
346 <td><p><span class="term"><em class="parameter"><code>mem_chunk</code></em> :</span></p></td>
347 <td> a <a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="type">GMemChunk</span></a>.
351 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
352 <td> a pointer to the allocated atom.
359 <div class="refsect2" title="g_mem_chunk_free ()">
360 <a name="g-mem-chunk-free"></a><h3>g_mem_chunk_free ()</h3>
361 <pre class="programlisting"><span class="returnvalue">void</span> g_mem_chunk_free (<a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="returnvalue">GMemChunk</span></a> *mem_chunk,
362 <a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="returnvalue">gpointer</span></a> mem);</pre>
363 <div class="warning" title="Warning" style="margin-left: 0.5in; margin-right: 0.5in;">
364 <h3 class="title">Warning</h3>
365 <p><code class="literal">g_mem_chunk_free</code> has been deprecated since version 2.10 and should not be used in newly-written code. Use <a class="link" href="glib-Memory-Slices.html#g-slice-free1" title="g_slice_free1 ()"><code class="function">g_slice_free1()</code></a> instead</p>
368 Frees an atom in a <a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="type">GMemChunk</span></a>. This should only be called if the
369 <a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="type">GMemChunk</span></a> was created with <a class="link" href="glib-Memory-Chunks.html#G-ALLOC-AND-FREE:CAPS" title="G_ALLOC_AND_FREE"><span class="type">G_ALLOC_AND_FREE</span></a>. Otherwise it will
371 <div class="variablelist"><table border="0">
372 <col align="left" valign="top">
375 <td><p><span class="term"><em class="parameter"><code>mem_chunk</code></em> :</span></p></td>
376 <td> a <a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="type">GMemChunk</span></a>.
380 <td><p><span class="term"><em class="parameter"><code>mem</code></em> :</span></p></td>
381 <td> a pointer to the atom to free.
388 <div class="refsect2" title="g_mem_chunk_destroy ()">
389 <a name="g-mem-chunk-destroy"></a><h3>g_mem_chunk_destroy ()</h3>
390 <pre class="programlisting"><span class="returnvalue">void</span> g_mem_chunk_destroy (<a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="returnvalue">GMemChunk</span></a> *mem_chunk);</pre>
391 <div class="warning" title="Warning" style="margin-left: 0.5in; margin-right: 0.5in;">
392 <h3 class="title">Warning</h3>
393 <p><code class="literal">g_mem_chunk_destroy</code> has been deprecated since version 2.10 and should not be used in newly-written code. Use the <a class="link" href="glib-Memory-Slices.html" title="Memory Slices">slice
394 allocator</a> instead</p>
397 Frees all of the memory allocated for a <a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="type">GMemChunk</span></a>.</p>
398 <div class="variablelist"><table border="0">
399 <col align="left" valign="top">
401 <td><p><span class="term"><em class="parameter"><code>mem_chunk</code></em> :</span></p></td>
402 <td> a <a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="type">GMemChunk</span></a>.
408 <div class="refsect2" title="g_mem_chunk_create()">
409 <a name="g-mem-chunk-create"></a><h3>g_mem_chunk_create()</h3>
410 <pre class="programlisting">#define g_mem_chunk_create(type, pre_alloc, alloc_type)</pre>
411 <div class="warning" title="Warning" style="margin-left: 0.5in; margin-right: 0.5in;">
412 <h3 class="title">Warning</h3>
413 <p><code class="literal">g_mem_chunk_create</code> has been deprecated since version 2.10 and should not be used in newly-written code. Use the <a class="link" href="glib-Memory-Slices.html" title="Memory Slices">slice
414 allocator</a> instead</p>
417 A convenience macro for creating a new <a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="type">GMemChunk</span></a>. It calls
418 <a class="link" href="glib-Memory-Chunks.html#g-mem-chunk-new" title="g_mem_chunk_new ()"><code class="function">g_mem_chunk_new()</code></a>, using the given type to create the <a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="type">GMemChunk</span></a>
419 name. The atom size is determined using
420 <code class="function"><code class="function">sizeof()</code></code>, and the area size is calculated by
421 multiplying the <em class="parameter"><code>pre_alloc</code></em> parameter with the atom size.</p>
422 <div class="variablelist"><table border="0">
423 <col align="left" valign="top">
426 <td><p><span class="term"><em class="parameter"><code>type</code></em> :</span></p></td>
427 <td> the type of the atoms, typically a structure name.
431 <td><p><span class="term"><em class="parameter"><code>pre_alloc</code></em> :</span></p></td>
432 <td> the number of atoms to store in each block of memory.
436 <td><p><span class="term"><em class="parameter"><code>alloc_type</code></em> :</span></p></td>
437 <td> the type of the <a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="type">GMemChunk</span></a>. <a class="link" href="glib-Memory-Chunks.html#G-ALLOC-AND-FREE:CAPS" title="G_ALLOC_AND_FREE"><span class="type">G_ALLOC_AND_FREE</span></a> is used
438 if the atoms will be freed individually. <a class="link" href="glib-Memory-Chunks.html#G-ALLOC-ONLY:CAPS" title="G_ALLOC_ONLY"><span class="type">G_ALLOC_ONLY</span></a>
439 should be used if atoms will never be freed
440 individually. <a class="link" href="glib-Memory-Chunks.html#G-ALLOC-ONLY:CAPS" title="G_ALLOC_ONLY"><span class="type">G_ALLOC_ONLY</span></a> is quicker, since it does
441 not need to track free atoms, but it obviously wastes
442 memory if you no longer need many of the atoms.
446 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
447 <td> the new <a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="type">GMemChunk</span></a>.
454 <div class="refsect2" title="g_chunk_new()">
455 <a name="g-chunk-new"></a><h3>g_chunk_new()</h3>
456 <pre class="programlisting">#define g_chunk_new(type, chunk)</pre>
457 <div class="warning" title="Warning" style="margin-left: 0.5in; margin-right: 0.5in;">
458 <h3 class="title">Warning</h3>
459 <p><code class="literal">g_chunk_new</code> has been deprecated since version 2.10 and should not be used in newly-written code. Use <a class="link" href="glib-Memory-Slices.html#g-slice-new" title="g_slice_new()"><code class="function">g_slice_new()</code></a> instead</p>
462 A convenience macro to allocate an atom of memory from a <a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="type">GMemChunk</span></a>.
463 It calls <a class="link" href="glib-Memory-Chunks.html#g-mem-chunk-alloc" title="g_mem_chunk_alloc ()"><code class="function">g_mem_chunk_alloc()</code></a> and casts the returned atom to a
464 pointer to the given type, avoiding a type cast in the source code.</p>
465 <div class="variablelist"><table border="0">
466 <col align="left" valign="top">
469 <td><p><span class="term"><em class="parameter"><code>type</code></em> :</span></p></td>
470 <td> the type of the <a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="type">GMemChunk</span></a> atoms, typically a structure name.
474 <td><p><span class="term"><em class="parameter"><code>chunk</code></em> :</span></p></td>
475 <td> a <a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="type">GMemChunk</span></a>.
479 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
480 <td> a pointer to the allocated atom, cast to a pointer to
481 <em class="parameter"><code>type</code></em>.
488 <div class="refsect2" title="g_chunk_new0()">
489 <a name="g-chunk-new0"></a><h3>g_chunk_new0()</h3>
490 <pre class="programlisting">#define g_chunk_new0(type, chunk)</pre>
491 <div class="warning" title="Warning" style="margin-left: 0.5in; margin-right: 0.5in;">
492 <h3 class="title">Warning</h3>
493 <p><code class="literal">g_chunk_new0</code> has been deprecated since version 2.10 and should not be used in newly-written code. Use <a class="link" href="glib-Memory-Slices.html#g-slice-new0" title="g_slice_new0()"><code class="function">g_slice_new0()</code></a> instead</p>
496 A convenience macro to allocate an atom of memory from a <a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="type">GMemChunk</span></a>.
497 It calls <a class="link" href="glib-Memory-Chunks.html#g-mem-chunk-alloc0" title="g_mem_chunk_alloc0 ()"><code class="function">g_mem_chunk_alloc0()</code></a> and casts the returned atom to a
498 pointer to the given type, avoiding a type cast in the source code.</p>
499 <div class="variablelist"><table border="0">
500 <col align="left" valign="top">
503 <td><p><span class="term"><em class="parameter"><code>type</code></em> :</span></p></td>
504 <td> the type of the <a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="type">GMemChunk</span></a> atoms, typically a structure name.
508 <td><p><span class="term"><em class="parameter"><code>chunk</code></em> :</span></p></td>
509 <td> a <a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="type">GMemChunk</span></a>.
513 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
514 <td> a pointer to the allocated atom, cast to a pointer to
515 <em class="parameter"><code>type</code></em>.
522 <div class="refsect2" title="g_chunk_free()">
523 <a name="g-chunk-free"></a><h3>g_chunk_free()</h3>
524 <pre class="programlisting">#define g_chunk_free(mem, mem_chunk)</pre>
525 <div class="warning" title="Warning" style="margin-left: 0.5in; margin-right: 0.5in;">
526 <h3 class="title">Warning</h3>
527 <p><code class="literal">g_chunk_free</code> has been deprecated since version 2.10 and should not be used in newly-written code. Use <a class="link" href="glib-Memory-Slices.html#g-slice-free" title="g_slice_free()"><code class="function">g_slice_free()</code></a> instead</p>
530 A convenience macro to free an atom of memory from a <a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="type">GMemChunk</span></a>. It
531 simply switches the arguments and calls <a class="link" href="glib-Memory-Chunks.html#g-mem-chunk-free" title="g_mem_chunk_free ()"><code class="function">g_mem_chunk_free()</code></a> It is
532 included simply to complement the other convenience macros,
533 <a class="link" href="glib-Memory-Chunks.html#g-chunk-new" title="g_chunk_new()"><code class="function">g_chunk_new()</code></a> and <a class="link" href="glib-Memory-Chunks.html#g-chunk-new0" title="g_chunk_new0()"><code class="function">g_chunk_new0()</code></a>.</p>
534 <div class="variablelist"><table border="0">
535 <col align="left" valign="top">
538 <td><p><span class="term"><em class="parameter"><code>mem</code></em> :</span></p></td>
539 <td> a pointer to the atom to be freed.
543 <td><p><span class="term"><em class="parameter"><code>mem_chunk</code></em> :</span></p></td>
544 <td> a <a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="type">GMemChunk</span></a>.
551 <div class="refsect2" title="g_mem_chunk_reset ()">
552 <a name="g-mem-chunk-reset"></a><h3>g_mem_chunk_reset ()</h3>
553 <pre class="programlisting"><span class="returnvalue">void</span> g_mem_chunk_reset (<a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="returnvalue">GMemChunk</span></a> *mem_chunk);</pre>
554 <div class="warning" title="Warning" style="margin-left: 0.5in; margin-right: 0.5in;">
555 <h3 class="title">Warning</h3>
556 <p><code class="literal">g_mem_chunk_reset</code> has been deprecated since version 2.10 and should not be used in newly-written code. Use the <a class="link" href="glib-Memory-Slices.html" title="Memory Slices">slice
557 allocator</a> instead</p>
560 Resets a GMemChunk to its initial state. It frees all of the
561 currently allocated blocks of memory.</p>
562 <div class="variablelist"><table border="0">
563 <col align="left" valign="top">
565 <td><p><span class="term"><em class="parameter"><code>mem_chunk</code></em> :</span></p></td>
566 <td> a <a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="type">GMemChunk</span></a>.
572 <div class="refsect2" title="g_mem_chunk_clean ()">
573 <a name="g-mem-chunk-clean"></a><h3>g_mem_chunk_clean ()</h3>
574 <pre class="programlisting"><span class="returnvalue">void</span> g_mem_chunk_clean (<a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="returnvalue">GMemChunk</span></a> *mem_chunk);</pre>
575 <div class="warning" title="Warning" style="margin-left: 0.5in; margin-right: 0.5in;">
576 <h3 class="title">Warning</h3>
577 <p><code class="literal">g_mem_chunk_clean</code> has been deprecated since version 2.10 and should not be used in newly-written code. Use the <a class="link" href="glib-Memory-Slices.html" title="Memory Slices">slice
578 allocator</a> instead</p>
581 Frees any blocks in a <a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="type">GMemChunk</span></a> which are no longer being used.</p>
582 <div class="variablelist"><table border="0">
583 <col align="left" valign="top">
585 <td><p><span class="term"><em class="parameter"><code>mem_chunk</code></em> :</span></p></td>
586 <td> a <a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="type">GMemChunk</span></a>.
592 <div class="refsect2" title="g_blow_chunks ()">
593 <a name="g-blow-chunks"></a><h3>g_blow_chunks ()</h3>
594 <pre class="programlisting"><span class="returnvalue">void</span> g_blow_chunks (void);</pre>
595 <div class="warning" title="Warning" style="margin-left: 0.5in; margin-right: 0.5in;">
596 <h3 class="title">Warning</h3>
597 <p><code class="literal">g_blow_chunks</code> has been deprecated since version 2.10 and should not be used in newly-written code. Use the <a class="link" href="glib-Memory-Slices.html" title="Memory Slices">slice
598 allocator</a> instead</p>
601 Calls <a class="link" href="glib-Memory-Chunks.html#g-mem-chunk-clean" title="g_mem_chunk_clean ()"><code class="function">g_mem_chunk_clean()</code></a> on all <a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="type">GMemChunk</span></a> objects.</p>
604 <div class="refsect2" title="g_mem_chunk_info ()">
605 <a name="g-mem-chunk-info"></a><h3>g_mem_chunk_info ()</h3>
606 <pre class="programlisting"><span class="returnvalue">void</span> g_mem_chunk_info (void);</pre>
607 <div class="warning" title="Warning" style="margin-left: 0.5in; margin-right: 0.5in;">
608 <h3 class="title">Warning</h3>
609 <p><code class="literal">g_mem_chunk_info</code> has been deprecated since version 2.10 and should not be used in newly-written code. Use the <a class="link" href="glib-Memory-Slices.html" title="Memory Slices">slice
610 allocator</a> instead</p>
613 Outputs debugging information for all <a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="type">GMemChunk</span></a> objects currently
614 in use. It outputs the number of <a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="type">GMemChunk</span></a> objects currently
615 allocated, and calls <a class="link" href="glib-Memory-Chunks.html#g-mem-chunk-print" title="g_mem_chunk_print ()"><code class="function">g_mem_chunk_print()</code></a> to output information on
619 <div class="refsect2" title="g_mem_chunk_print ()">
620 <a name="g-mem-chunk-print"></a><h3>g_mem_chunk_print ()</h3>
621 <pre class="programlisting"><span class="returnvalue">void</span> g_mem_chunk_print (<a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="returnvalue">GMemChunk</span></a> *mem_chunk);</pre>
622 <div class="warning" title="Warning" style="margin-left: 0.5in; margin-right: 0.5in;">
623 <h3 class="title">Warning</h3>
624 <p><code class="literal">g_mem_chunk_print</code> has been deprecated since version 2.10 and should not be used in newly-written code. Use the <a class="link" href="glib-Memory-Slices.html" title="Memory Slices">slice
625 allocator</a> instead</p>
628 Outputs debugging information for a <a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="type">GMemChunk</span></a>. It outputs the name
629 of the <a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="type">GMemChunk</span></a> (set with <a class="link" href="glib-Memory-Chunks.html#g-mem-chunk-new" title="g_mem_chunk_new ()"><code class="function">g_mem_chunk_new()</code></a>), the number of bytes
630 used, and the number of blocks of memory allocated.</p>
631 <div class="variablelist"><table border="0">
632 <col align="left" valign="top">
634 <td><p><span class="term"><em class="parameter"><code>mem_chunk</code></em> :</span></p></td>
635 <td> a <a class="link" href="glib-Memory-Chunks.html#GMemChunk" title="GMemChunk"><span class="type">GMemChunk</span></a>.
644 Generated by GTK-Doc V1.13</div>