~ubuntu-branches/debian/jessie/glib2.0/jessie

« back to all changes in this revision

Viewing changes to docs/reference/glib/html/glib-Memory-Slices.html

  • Committer: Bazaar Package Importer
  • Author(s): Gustavo Noronha Silva
  • Date: 2009-02-15 13:00:43 UTC
  • mto: (1.4.3 upstream)
  • mto: This revision was merged to the branch mainline in revision 70.
  • Revision ID: james.westby@ubuntu.com-20090215130043-6snh45flhit8oalb
Tags: upstream-2.18.4
Import upstream version 2.18.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2
2
<html>
3
3
<head>
4
 
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
 
4
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5
5
<title>Memory Slices</title>
6
 
<meta name="generator" content="DocBook XSL Stylesheets V1.73.2">
7
 
<link rel="start" href="index.html" title="GLib Reference Manual">
 
6
<meta name="generator" content="DocBook XSL Stylesheets V1.74.0">
 
7
<link rel="home" href="index.html" title="GLib Reference Manual">
8
8
<link rel="up" href="glib-data-types.html" title="GLib Data Types">
9
9
<link rel="prev" href="glib-data-types.html" title="GLib Data Types">
10
10
<link rel="next" href="glib-Memory-Chunks.html" title="Memory Chunks">
11
 
<meta name="generator" content="GTK-Doc V1.9 (XML mode)">
 
11
<meta name="generator" content="GTK-Doc V1.11 (XML mode)">
12
12
<link rel="stylesheet" href="style.css" type="text/css">
13
13
<link rel="chapter" href="glib.html" title="GLib Overview">
14
14
<link rel="chapter" href="glib-fundamentals.html" title="GLib Fundamentals">
26
26
<link rel="index" href="ix08.html" title="Index of new symbols in 2.12">
27
27
<link rel="index" href="ix09.html" title="Index of new symbols in 2.14">
28
28
<link rel="index" href="ix10.html" title="Index of new symbols in 2.16">
 
29
<link rel="index" href="ix11.html" title="Index of new symbols in 2.18">
29
30
</head>
30
31
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
31
32
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2">
36
37
<th width="100%" align="center">GLib Reference Manual</th>
37
38
<td><a accesskey="n" href="glib-Memory-Chunks.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
38
39
</tr>
39
 
<tr><td colspan="5" class="shortcuts"><nobr><a href="#id3286227" class="shortcut">Top</a>
40
 
                  &#160;|&#160;
41
 
                  <a href="#id3286431" class="shortcut">Description</a></nobr></td></tr>
 
40
<tr><td colspan="5" class="shortcuts">
 
41
<a href="#glib-Memory-Slices.synopsis" class="shortcut">Top</a>
 
42
                 | 
 
43
                <a href="#glib-Memory-Slices.description" class="shortcut">Description</a>
 
44
</td></tr>
42
45
</table>
43
46
<div class="refentry" lang="en">
44
47
<a name="glib-Memory-Slices"></a><div class="titlepage"></div>
45
48
<div class="refnamediv"><table width="100%"><tr>
46
49
<td valign="top">
47
 
<h2>
48
 
<a name="id3286227"></a><span class="refentrytitle">Memory Slices</span>
49
 
</h2>
50
 
<p>Memory Slices &#8212; efficient way to allocate groups of equal-sized chunks of memory</p>
 
50
<h2><span class="refentrytitle"><a name="glib-Memory-Slices.top_of_page"></a>Memory Slices</span></h2>
 
51
<p>Memory Slices — efficient way to allocate groups of equal-sized chunks of memory</p>
51
52
</td>
52
53
<td valign="top" align="right"></td>
53
54
</tr></table></div>
54
55
<div class="refsynopsisdiv">
55
 
<h2>Synopsis</h2>
 
56
<a name="glib-Memory-Slices.synopsis"></a><h2>Synopsis</h2>
56
57
<pre class="synopsis">
57
58
 
58
59
#include &lt;glib.h&gt;
59
60
 
60
 
 
61
 
<a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a>            <a class="link" href="glib-Memory-Slices.html#g-slice-alloc">g_slice_alloc</a>                       (<a class="link" href="glib-Basic-Types.html#gsize">gsize</a> block_size);
62
 
<a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a>            <a class="link" href="glib-Memory-Slices.html#g-slice-alloc0">g_slice_alloc0</a>                      (<a class="link" href="glib-Basic-Types.html#gsize">gsize</a> block_size);
63
 
<a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a>            <a class="link" href="glib-Memory-Slices.html#g-slice-copy">g_slice_copy</a>                        (<a class="link" href="glib-Basic-Types.html#gsize">gsize</a> block_size,
64
 
                                                         <a class="link" href="glib-Basic-Types.html#gconstpointer">gconstpointer</a> mem_block);
65
 
void                <a class="link" href="glib-Memory-Slices.html#g-slice-free1">g_slice_free1</a>                       (<a class="link" href="glib-Basic-Types.html#gsize">gsize</a> block_size,
66
 
                                                         <a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> mem_block);
67
 
void                <a class="link" href="glib-Memory-Slices.html#g-slice-free-chain-with-offset">g_slice_free_chain_with_offset</a>      (<a class="link" href="glib-Basic-Types.html#gsize">gsize</a> block_size,
68
 
                                                         <a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> mem_chain,
69
 
                                                         <a class="link" href="glib-Basic-Types.html#gsize">gsize</a> next_offset);
70
 
 
71
 
#define             <a class="link" href="glib-Memory-Slices.html#g-slice-new">g_slice_new</a>                         (type)
72
 
#define             <a class="link" href="glib-Memory-Slices.html#g-slice-new0">g_slice_new0</a>                        (type)
73
 
#define             <a class="link" href="glib-Memory-Slices.html#g-slice-dup">g_slice_dup</a>                         (type, mem)
74
 
#define             <a class="link" href="glib-Memory-Slices.html#g-slice-free">g_slice_free</a>                        (type, mem)
75
 
#define             <a class="link" href="glib-Memory-Slices.html#g-slice-free-chain">g_slice_free_chain</a>                  (type, mem_chain, next)
76
 
 
 
61
<a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer">gpointer</a>            <a class="link" href="glib-Memory-Slices.html#g-slice-alloc" title="g_slice_alloc ()">g_slice_alloc</a>                       (<a class="link" href="glib-Basic-Types.html#gsize" title="gsize">gsize</a> block_size);
 
62
<a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer">gpointer</a>            <a class="link" href="glib-Memory-Slices.html#g-slice-alloc0" title="g_slice_alloc0 ()">g_slice_alloc0</a>                      (<a class="link" href="glib-Basic-Types.html#gsize" title="gsize">gsize</a> block_size);
 
63
<a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer">gpointer</a>            <a class="link" href="glib-Memory-Slices.html#g-slice-copy" title="g_slice_copy ()">g_slice_copy</a>                        (<a class="link" href="glib-Basic-Types.html#gsize" title="gsize">gsize</a> block_size,
 
64
                                                         <a class="link" href="glib-Basic-Types.html#gconstpointer" title="gconstpointer">gconstpointer</a> mem_block);
 
65
void                <a class="link" href="glib-Memory-Slices.html#g-slice-free1" title="g_slice_free1 ()">g_slice_free1</a>                       (<a class="link" href="glib-Basic-Types.html#gsize" title="gsize">gsize</a> block_size,
 
66
                                                         <a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer">gpointer</a> mem_block);
 
67
void                <a class="link" href="glib-Memory-Slices.html#g-slice-free-chain-with-offset" title="g_slice_free_chain_with_offset ()">g_slice_free_chain_with_offset</a>      (<a class="link" href="glib-Basic-Types.html#gsize" title="gsize">gsize</a> block_size,
 
68
                                                         <a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer">gpointer</a> mem_chain,
 
69
                                                         <a class="link" href="glib-Basic-Types.html#gsize" title="gsize">gsize</a> next_offset);
 
70
 
 
71
#define             <a class="link" href="glib-Memory-Slices.html#g-slice-new" title="g_slice_new()">g_slice_new</a>                         (type)
 
72
#define             <a class="link" href="glib-Memory-Slices.html#g-slice-new0" title="g_slice_new0()">g_slice_new0</a>                        (type)
 
73
#define             <a class="link" href="glib-Memory-Slices.html#g-slice-dup" title="g_slice_dup()">g_slice_dup</a>                         (type, mem)
 
74
#define             <a class="link" href="glib-Memory-Slices.html#g-slice-free" title="g_slice_free()">g_slice_free</a>                        (type, mem)
 
75
#define             <a class="link" href="glib-Memory-Slices.html#g-slice-free-chain" title="g_slice_free_chain()">g_slice_free_chain</a>                  (type, mem_chain, next)
77
76
</pre>
78
77
</div>
79
78
<div class="refsect1" lang="en">
80
 
<a name="id3286431"></a><h2>Description</h2>
 
79
<a name="glib-Memory-Slices.description"></a><h2>Description</h2>
81
80
<p>
82
81
Memory slices provide a space-efficient and multi-processing scalable
83
82
way to allocate equal-sized pieces of memory, just like the original
85
84
memory-waste, scalability and performance problems.
86
85
</p>
87
86
<p>
88
 
To achieve these goals, the slice allocator uses a sophisticated, 
 
87
To achieve these goals, the slice allocator uses a sophisticated,
89
88
layered design that has been inspired by Bonwick's slab allocator
90
 
<sup>[<a name="id3286464" href="#ftn.id3286464" class="footnote">6</a>]</sup>.
91
 
It uses <code class="function">posix_memalign()</code> to optimize allocations of many equally-sized 
92
 
chunks, and has per-thread free lists (the so-called magazine layer) 
93
 
to quickly satisfy allocation requests of already known structure sizes. 
94
 
This is accompanied by extra caching logic to keep freed memory around 
95
 
for some time before returning it to the system. Memory that is unused 
96
 
due to alignment constraints is used for cache colorization (random 
97
 
distribution of chunk addresses) to improve CPU cache utilization. The 
98
 
caching layer of the slice allocator adapts itself to high lock contention 
 
89
<sup>[<a name="id3337918" href="#ftn.id3337918" class="footnote">6</a>]</sup>.
 
90
It uses <code class="function">posix_memalign()</code> to optimize allocations of many equally-sized
 
91
chunks, and has per-thread free lists (the so-called magazine layer)
 
92
to quickly satisfy allocation requests of already known structure sizes.
 
93
This is accompanied by extra caching logic to keep freed memory around
 
94
for some time before returning it to the system. Memory that is unused
 
95
due to alignment constraints is used for cache colorization (random
 
96
distribution of chunk addresses) to improve CPU cache utilization. The
 
97
caching layer of the slice allocator adapts itself to high lock contention
99
98
to improve scalability.
100
99
</p>
101
100
<p>
102
101
The slice allocator can allocate blocks as small as two pointers, and
103
 
unlike <code class="function">malloc()</code>, it does not reserve extra space per block. For large block 
104
 
sizes, <a class="link" href="glib-Memory-Slices.html#g-slice-new"><code class="function">g_slice_new()</code></a> and <a class="link" href="glib-Memory-Slices.html#g-slice-alloc"><code class="function">g_slice_alloc()</code></a> will automatically delegate to the
 
102
unlike <code class="function">malloc()</code>, it does not reserve extra space per block. For large block
 
103
sizes, <a class="link" href="glib-Memory-Slices.html#g-slice-new" title="g_slice_new()"><code class="function">g_slice_new()</code></a> and <a class="link" href="glib-Memory-Slices.html#g-slice-alloc" title="g_slice_alloc ()"><code class="function">g_slice_alloc()</code></a> will automatically delegate to the
105
104
system <code class="function">malloc()</code> implementation. For newly written code it is recommended
106
 
to use the new <code class="literal">g_slice</code> API instead of <a class="link" href="glib-Memory-Allocation.html#g-malloc"><code class="function">g_malloc()</code></a> and 
107
 
friends, as long as objects are not resized during their lifetime and the 
 
105
to use the new <code class="literal">g_slice</code> API instead of <a class="link" href="glib-Memory-Allocation.html#g-malloc" title="g_malloc ()"><code class="function">g_malloc()</code></a> and
 
106
friends, as long as objects are not resized during their lifetime and the
108
107
object size used at allocation time is still available when freeing.
109
108
</p>
110
109
<div class="example">
111
 
<a name="id3286586"></a><p class="title"><b>Example&#160;15.&#160;Using the slice allocator</b></p>
 
110
<a name="id3338038"></a><p class="title"><b>Example 15. Using the slice allocator</b></p>
112
111
<div class="example-contents"><pre class="programlisting">
113
112
  gchar *mem[10000];
114
113
  gint i;
115
 
 
116
114
  /* Allocate 10000 blocks. */
117
115
  for (i = 0; i &lt; 10000; i++)
118
116
    {
119
117
      mem[i] = g_slice_alloc (50);
120
 
 
121
118
      /* Fill in the memory with some junk. */
122
119
      for (j = 0; j &lt; 50; j++)
123
120
        mem[i][j] = i * j;
124
121
    }
125
 
 
126
122
  /* Now free all of the blocks. */
127
123
  for (i = 0; i &lt; 10000; i++)
128
124
    {
131
127
</pre></div>
132
128
</div>
133
129
<br class="example-break"><div class="example">
134
 
<a name="id3286607"></a><p class="title"><b>Example&#160;16.&#160;Using the slice allocator with data structures</b></p>
 
130
<a name="id3338059"></a><p class="title"><b>Example 16. Using the slice allocator with data structures</b></p>
135
131
<div class="example-contents"><pre class="programlisting">
136
132
  GRealArray *array;
137
 
 
138
133
  /* Allocate one block, using the g_slice_new() macro. */
139
134
  array = g_slice_new (GRealArray);
140
 
 
141
135
  /* We can now use array just like a normal pointer to a structure. */
142
136
  array-&gt;data            = NULL;
143
137
  array-&gt;len             = 0;
145
139
  array-&gt;zero_terminated = (zero_terminated ? 1 : 0);
146
140
  array-&gt;clear           = (clear ? 1 : 0);
147
141
  array-&gt;elt_size        = elt_size;
148
 
 
149
142
  /* We can free the block, so it can be reused. */
150
143
  g_slice_free (GRealArray, array);
151
144
</pre></div>
153
146
<br class="example-break">
154
147
</div>
155
148
<div class="refsect1" lang="en">
156
 
<a name="id3286631"></a><h2>Details</h2>
 
149
<a name="glib-Memory-Slices.details"></a><h2>Details</h2>
157
150
<div class="refsect2" lang="en">
158
 
<a name="id3286641"></a><h3>
159
 
<a name="g-slice-alloc"></a>g_slice_alloc ()</h3>
160
 
<a class="indexterm" name="id3286656"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a>            g_slice_alloc                       (<a class="link" href="glib-Basic-Types.html#gsize">gsize</a> block_size);</pre>
 
151
<a name="g-slice-alloc"></a><h3>g_slice_alloc ()</h3>
 
152
<pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer">gpointer</a>            g_slice_alloc                       (<a class="link" href="glib-Basic-Types.html#gsize" title="gsize">gsize</a> block_size);</pre>
161
153
<p>
162
154
Allocates a block of memory from the slice allocator.
163
155
The block adress handed out can be expected to be aligned
173
165
<col align="left" valign="top">
174
166
<tbody>
175
167
<tr>
176
 
<td><p><span class="term"><em class="parameter"><code>block_size</code></em>&#160;:</span></p></td>
 
168
<td><p><span class="term"><em class="parameter"><code>block_size</code></em> :</span></p></td>
177
169
<td>the number of bytes to allocate
178
170
</td>
179
171
</tr>
180
172
<tr>
181
 
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td>
 
173
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
182
174
<td>a pointer to the allocated memory block
183
175
</td>
184
176
</tr>
185
177
</tbody>
186
178
</table></div>
187
 
<p class="since">Since 2.10
188
 
 
189
 
 
190
 
</p>
 
179
<p class="since">Since 2.10</p>
191
180
</div>
192
181
<hr>
193
182
<div class="refsect2" lang="en">
194
 
<a name="id3286752"></a><h3>
195
 
<a name="g-slice-alloc0"></a>g_slice_alloc0 ()</h3>
196
 
<a class="indexterm" name="id3286767"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a>            g_slice_alloc0                      (<a class="link" href="glib-Basic-Types.html#gsize">gsize</a> block_size);</pre>
 
183
<a name="g-slice-alloc0"></a><h3>g_slice_alloc0 ()</h3>
 
184
<pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer">gpointer</a>            g_slice_alloc0                      (<a class="link" href="glib-Basic-Types.html#gsize" title="gsize">gsize</a> block_size);</pre>
197
185
<p>
198
 
Allocates a block of memory via <a class="link" href="glib-Memory-Slices.html#g-slice-alloc"><code class="function">g_slice_alloc()</code></a>
 
186
Allocates a block of memory via <a class="link" href="glib-Memory-Slices.html#g-slice-alloc" title="g_slice_alloc ()"><code class="function">g_slice_alloc()</code></a>
199
187
and initialize the returned memory to 0.
200
188
Note that the underlying slice allocation mechanism can
201
189
be changed with the <a class="link" href="glib-running.html#G_SLICE" title="G_SLICE">G_SLICE=always-malloc</a>
205
193
<col align="left" valign="top">
206
194
<tbody>
207
195
<tr>
208
 
<td><p><span class="term"><em class="parameter"><code>block_size</code></em>&#160;:</span></p></td>
 
196
<td><p><span class="term"><em class="parameter"><code>block_size</code></em> :</span></p></td>
209
197
<td>the number of bytes to allocate
210
198
</td>
211
199
</tr>
212
200
<tr>
213
 
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td>
 
201
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
214
202
<td>a pointer to the allocated block
215
203
</td>
216
204
</tr>
217
205
</tbody>
218
206
</table></div>
219
 
<p class="since">Since 2.10
220
 
 
221
 
 
222
 
</p>
 
207
<p class="since">Since 2.10</p>
223
208
</div>
224
209
<hr>
225
210
<div class="refsect2" lang="en">
226
 
<a name="id3286852"></a><h3>
227
 
<a name="g-slice-copy"></a>g_slice_copy ()</h3>
228
 
<a class="indexterm" name="id3286868"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a>            g_slice_copy                        (<a class="link" href="glib-Basic-Types.html#gsize">gsize</a> block_size,
229
 
                                                         <a class="link" href="glib-Basic-Types.html#gconstpointer">gconstpointer</a> mem_block);</pre>
 
211
<a name="g-slice-copy"></a><h3>g_slice_copy ()</h3>
 
212
<pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer">gpointer</a>            g_slice_copy                        (<a class="link" href="glib-Basic-Types.html#gsize" title="gsize">gsize</a> block_size,
 
213
                                                         <a class="link" href="glib-Basic-Types.html#gconstpointer" title="gconstpointer">gconstpointer</a> mem_block);</pre>
230
214
<p>
231
215
Allocates a block of memory from the slice allocator and copies
232
216
<em class="parameter"><code>block_size</code></em> bytes into it from <em class="parameter"><code>mem_block</code></em>.
235
219
<col align="left" valign="top">
236
220
<tbody>
237
221
<tr>
238
 
<td><p><span class="term"><em class="parameter"><code>block_size</code></em>&#160;:</span></p></td>
 
222
<td><p><span class="term"><em class="parameter"><code>block_size</code></em> :</span></p></td>
239
223
<td>the number of bytes to allocate
240
224
</td>
241
225
</tr>
242
226
<tr>
243
 
<td><p><span class="term"><em class="parameter"><code>mem_block</code></em>&#160;:</span></p></td>
 
227
<td><p><span class="term"><em class="parameter"><code>mem_block</code></em> :</span></p></td>
244
228
<td>the memory to copy
245
229
</td>
246
230
</tr>
247
231
<tr>
248
 
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td>
 
232
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
249
233
<td>a pointer to the allocated memory block
250
234
</td>
251
235
</tr>
252
236
</tbody>
253
237
</table></div>
254
 
<p class="since">Since 2.14
255
 
 
256
 
 
257
 
</p>
 
238
<p class="since">Since 2.14</p>
258
239
</div>
259
240
<hr>
260
241
<div class="refsect2" lang="en">
261
 
<a name="id3286968"></a><h3>
262
 
<a name="g-slice-free1"></a>g_slice_free1 ()</h3>
263
 
<a class="indexterm" name="id3286982"></a><pre class="programlisting">void                g_slice_free1                       (<a class="link" href="glib-Basic-Types.html#gsize">gsize</a> block_size,
264
 
                                                         <a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> mem_block);</pre>
 
242
<a name="g-slice-free1"></a><h3>g_slice_free1 ()</h3>
 
243
<pre class="programlisting">void                g_slice_free1                       (<a class="link" href="glib-Basic-Types.html#gsize" title="gsize">gsize</a> block_size,
 
244
                                                         <a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer">gpointer</a> mem_block);</pre>
265
245
<p>
266
246
Frees a block of memory. The memory must have been allocated via
267
 
<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>
 
247
<a class="link" href="glib-Memory-Slices.html#g-slice-alloc" title="g_slice_alloc ()"><code class="function">g_slice_alloc()</code></a> or <a class="link" href="glib-Memory-Slices.html#g-slice-alloc0" title="g_slice_alloc0 ()"><code class="function">g_slice_alloc0()</code></a>
268
248
and the <em class="parameter"><code>block_size</code></em> has to match the size specified upon allocation.
269
249
Note that the exact release behaviour can be changed with the
270
250
<a class="link" href="glib-running.html#G_DEBUG" title="G_DEBUG">G_DEBUG=gc-friendly</a> environment variable,
274
254
<col align="left" valign="top">
275
255
<tbody>
276
256
<tr>
277
 
<td><p><span class="term"><em class="parameter"><code>block_size</code></em>&#160;:</span></p></td>
 
257
<td><p><span class="term"><em class="parameter"><code>block_size</code></em> :</span></p></td>
278
258
<td>the size of the block
279
259
</td>
280
260
</tr>
281
261
<tr>
282
 
<td><p><span class="term"><em class="parameter"><code>mem_block</code></em>&#160;:</span></p></td>
 
262
<td><p><span class="term"><em class="parameter"><code>mem_block</code></em> :</span></p></td>
283
263
<td>a pointer to the block to free
284
264
</td>
285
265
</tr>
286
266
</tbody>
287
267
</table></div>
288
 
<p class="since">Since 2.10
289
 
 
290
 
 
291
 
</p>
 
268
<p class="since">Since 2.10</p>
292
269
</div>
293
270
<hr>
294
271
<div class="refsect2" lang="en">
295
 
<a name="id3287104"></a><h3>
296
 
<a name="g-slice-free-chain-with-offset"></a>g_slice_free_chain_with_offset ()</h3>
297
 
<a class="indexterm" name="id3287119"></a><pre class="programlisting">void                g_slice_free_chain_with_offset      (<a class="link" href="glib-Basic-Types.html#gsize">gsize</a> block_size,
298
 
                                                         <a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> mem_chain,
299
 
                                                         <a class="link" href="glib-Basic-Types.html#gsize">gsize</a> next_offset);</pre>
 
272
<a name="g-slice-free-chain-with-offset"></a><h3>g_slice_free_chain_with_offset ()</h3>
 
273
<pre class="programlisting">void                g_slice_free_chain_with_offset      (<a class="link" href="glib-Basic-Types.html#gsize" title="gsize">gsize</a> block_size,
 
274
                                                         <a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer">gpointer</a> mem_chain,
 
275
                                                         <a class="link" href="glib-Basic-Types.html#gsize" title="gsize">gsize</a> next_offset);</pre>
300
276
<p>
301
277
Frees a linked list of memory blocks of structure type <em class="parameter"><code>type</code></em>.
302
278
The memory blocks must be equal-sized, allocated via
303
 
<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>
304
 
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 
 
279
<a class="link" href="glib-Memory-Slices.html#g-slice-alloc" title="g_slice_alloc ()"><code class="function">g_slice_alloc()</code></a> or <a class="link" href="glib-Memory-Slices.html#g-slice-alloc0" title="g_slice_alloc0 ()"><code class="function">g_slice_alloc0()</code></a>
 
280
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" title="GSList"><span class="type">GSList</span></a>). The offset
305
281
of the <em class="parameter"><code>next</code></em> field in each block is passed as third argument.
306
282
Note that the exact release behaviour can be changed with the
307
283
<a class="link" href="glib-running.html#G_DEBUG" title="G_DEBUG">G_DEBUG=gc-friendly</a> environment variable,
311
287
<col align="left" valign="top">
312
288
<tbody>
313
289
<tr>
314
 
<td><p><span class="term"><em class="parameter"><code>block_size</code></em>&#160;:</span></p></td>
 
290
<td><p><span class="term"><em class="parameter"><code>block_size</code></em> :</span></p></td>
315
291
<td>the size of the blocks
316
292
</td>
317
293
</tr>
318
294
<tr>
319
 
<td><p><span class="term"><em class="parameter"><code>mem_chain</code></em>&#160;:</span></p></td>
 
295
<td><p><span class="term"><em class="parameter"><code>mem_chain</code></em> :</span></p></td>
320
296
<td> a pointer to the first block of the chain
321
297
</td>
322
298
</tr>
323
299
<tr>
324
 
<td><p><span class="term"><em class="parameter"><code>next_offset</code></em>&#160;:</span></p></td>
 
300
<td><p><span class="term"><em class="parameter"><code>next_offset</code></em> :</span></p></td>
325
301
<td>the offset of the <em class="parameter"><code>next</code></em> field in the blocks
326
302
</td>
327
303
</tr>
328
304
</tbody>
329
305
</table></div>
330
 
<p class="since">Since 2.10
331
 
 
332
 
 
333
 
</p>
 
306
<p class="since">Since 2.10</p>
334
307
</div>
335
308
<hr>
336
309
<div class="refsect2" lang="en">
337
 
<a name="id3287290"></a><h3>
338
 
<a name="g-slice-new"></a>g_slice_new()</h3>
339
 
<a class="indexterm" name="id3287305"></a><pre class="programlisting">#define             g_slice_new(type)</pre>
 
310
<a name="g-slice-new"></a><h3>g_slice_new()</h3>
 
311
<pre class="programlisting">#define             g_slice_new(type)</pre>
340
312
<p>
341
313
A convenience macro to allocate a block of memory from the slice allocator.
342
 
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 
343
 
the returned pointer to a pointer of the given type, avoiding a type cast 
 
314
It calls <a class="link" href="glib-Memory-Slices.html#g-slice-alloc" title="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
 
315
the returned pointer to a pointer of the given type, avoiding a type cast
344
316
in the source code.
345
317
Note that the underlying slice allocation mechanism can
346
318
be changed with the <a class="link" href="glib-running.html#G_SLICE" title="G_SLICE">G_SLICE=always-malloc</a>
350
322
<col align="left" valign="top">
351
323
<tbody>
352
324
<tr>
353
 
<td><p><span class="term"><em class="parameter"><code>type</code></em>&#160;:</span></p></td>
 
325
<td><p><span class="term"><em class="parameter"><code>type</code></em> :</span></p></td>
354
326
<td>the type to allocate, typically a structure name
355
327
</td>
356
328
</tr>
357
329
<tr>
358
 
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td>
 
330
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
359
331
<td>a pointer to the allocated block, cast to a pointer to <em class="parameter"><code>type</code></em>.
360
332
</td>
361
333
</tr>
362
334
</tbody>
363
335
</table></div>
364
 
<p class="since">Since 2.10
365
 
 
366
 
 
367
 
</p>
 
336
<p class="since">Since 2.10</p>
368
337
</div>
369
338
<hr>
370
339
<div class="refsect2" lang="en">
371
 
<a name="id3287398"></a><h3>
372
 
<a name="g-slice-new0"></a>g_slice_new0()</h3>
373
 
<a class="indexterm" name="id3287413"></a><pre class="programlisting">#define             g_slice_new0(type)</pre>
 
340
<a name="g-slice-new0"></a><h3>g_slice_new0()</h3>
 
341
<pre class="programlisting">#define             g_slice_new0(type)</pre>
374
342
<p>
375
343
A convenience macro to allocate a block of memory from the slice allocator
376
 
and 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 
377
 
<code class="literal">sizeof (<em class="parameter"><code>type</code></em>)</code> and casts the returned pointer to a pointer 
 
344
and set the memory to 0. It calls <a class="link" href="glib-Memory-Slices.html#g-slice-alloc0" title="g_slice_alloc0 ()"><code class="function">g_slice_alloc0()</code></a> with
 
345
<code class="literal">sizeof (<em class="parameter"><code>type</code></em>)</code> and casts the returned pointer to a pointer
378
346
of the given type, avoiding a type cast in the source code.
379
347
Note that the underlying slice allocation mechanism can
380
348
be changed with the <a class="link" href="glib-running.html#G_SLICE" title="G_SLICE">G_SLICE=always-malloc</a>
384
352
<col align="left" valign="top">
385
353
<tbody>
386
354
<tr>
387
 
<td><p><span class="term"><em class="parameter"><code>type</code></em>&#160;:</span></p></td>
 
355
<td><p><span class="term"><em class="parameter"><code>type</code></em> :</span></p></td>
388
356
<td>the type to allocate, typically a structure name
389
357
</td>
390
358
</tr>
391
359
<tr>
392
 
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td>
 
360
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
393
361
<td>a pointer to the allocated block, cast to a pointer to <em class="parameter"><code>type</code></em>.
394
362
</td>
395
363
</tr>
396
364
</tbody>
397
365
</table></div>
398
 
<p class="since">Since 2.10
399
 
 
400
 
 
401
 
</p>
 
366
<p class="since">Since 2.10</p>
402
367
</div>
403
368
<hr>
404
369
<div class="refsect2" lang="en">
405
 
<a name="id3287506"></a><h3>
406
 
<a name="g-slice-dup"></a>g_slice_dup()</h3>
407
 
<a class="indexterm" name="id3287520"></a><pre class="programlisting">#define             g_slice_dup(type, mem)</pre>
 
370
<a name="g-slice-dup"></a><h3>g_slice_dup()</h3>
 
371
<pre class="programlisting">#define             g_slice_dup(type, mem)</pre>
408
372
<p>
409
373
A convenience macro to duplicate a block of memory using the slice allocator.
410
 
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 
411
 
the returned pointer to a pointer of the given type, avoiding a type cast 
 
374
It calls <a class="link" href="glib-Memory-Slices.html#g-slice-copy" title="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
 
375
the returned pointer to a pointer of the given type, avoiding a type cast
412
376
in the source code.
413
377
Note that the underlying slice allocation mechanism can
414
378
be changed with the <a class="link" href="glib-running.html#G_SLICE" title="G_SLICE">G_SLICE=always-malloc</a>
418
382
<col align="left" valign="top">
419
383
<tbody>
420
384
<tr>
421
 
<td><p><span class="term"><em class="parameter"><code>type</code></em>&#160;:</span></p></td>
 
385
<td><p><span class="term"><em class="parameter"><code>type</code></em> :</span></p></td>
422
386
<td>the type to duplicate, typically a structure name
423
387
</td>
424
388
</tr>
425
389
<tr>
426
 
<td><p><span class="term"><em class="parameter"><code>mem</code></em>&#160;:</span></p></td>
 
390
<td><p><span class="term"><em class="parameter"><code>mem</code></em> :</span></p></td>
427
391
<td>the memory to copy into the allocated block
428
392
</td>
429
393
</tr>
430
394
<tr>
431
 
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td>
 
395
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
432
396
<td>a pointer to the allocated block, cast to a pointer to <em class="parameter"><code>type</code></em>.
433
397
</td>
434
398
</tr>
435
399
</tbody>
436
400
</table></div>
437
 
<p class="since">Since 2.14
438
 
 
439
 
 
440
 
</p>
 
401
<p class="since">Since 2.14</p>
441
402
</div>
442
403
<hr>
443
404
<div class="refsect2" lang="en">
444
 
<a name="id3287627"></a><h3>
445
 
<a name="g-slice-free"></a>g_slice_free()</h3>
446
 
<a class="indexterm" name="id3287642"></a><pre class="programlisting">#define             g_slice_free(type, mem)</pre>
 
405
<a name="g-slice-free"></a><h3>g_slice_free()</h3>
 
406
<pre class="programlisting">#define             g_slice_free(type, mem)</pre>
447
407
<p>
448
408
A convenience macro to free a block of memory that has been allocated
449
 
from 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 
 
409
from the slice allocator. It calls <a class="link" href="glib-Memory-Slices.html#g-slice-free1" title="g_slice_free1 ()"><code class="function">g_slice_free1()</code></a> using
450
410
<code class="literal">sizeof (type)</code> as the block size.
451
411
Note that the exact release behaviour can be changed with the
452
412
<a class="link" href="glib-running.html#G_DEBUG" title="G_DEBUG">G_DEBUG=gc-friendly</a> environment variable,
456
416
<col align="left" valign="top">
457
417
<tbody>
458
418
<tr>
459
 
<td><p><span class="term"><em class="parameter"><code>type</code></em>&#160;:</span></p></td>
 
419
<td><p><span class="term"><em class="parameter"><code>type</code></em> :</span></p></td>
460
420
<td>the type of the block to free, typically a structure name
461
421
</td>
462
422
</tr>
463
423
<tr>
464
 
<td><p><span class="term"><em class="parameter"><code>mem</code></em>&#160;:</span></p></td>
 
424
<td><p><span class="term"><em class="parameter"><code>mem</code></em> :</span></p></td>
465
425
<td>a pointer to the block to free
466
426
</td>
467
427
</tr>
468
428
</tbody>
469
429
</table></div>
470
 
<p class="since">Since 2.10
471
 
 
472
 
 
473
 
</p>
 
430
<p class="since">Since 2.10</p>
474
431
</div>
475
432
<hr>
476
433
<div class="refsect2" lang="en">
477
 
<a name="id3287732"></a><h3>
478
 
<a name="g-slice-free-chain"></a>g_slice_free_chain()</h3>
479
 
<a class="indexterm" name="id3287747"></a><pre class="programlisting">#define             g_slice_free_chain(type, mem_chain, next)</pre>
 
434
<a name="g-slice-free-chain"></a><h3>g_slice_free_chain()</h3>
 
435
<pre class="programlisting">#define             g_slice_free_chain(type, mem_chain, next)</pre>
480
436
<p>
481
437
Frees a linked list of memory blocks of structure type <em class="parameter"><code>type</code></em>.
482
438
The memory blocks must be equal-sized, allocated via
483
 
<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 
484
 
<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
 
439
<a class="link" href="glib-Memory-Slices.html#g-slice-alloc" title="g_slice_alloc ()"><code class="function">g_slice_alloc()</code></a> or <a class="link" href="glib-Memory-Slices.html#g-slice-alloc0" title="g_slice_alloc0 ()"><code class="function">g_slice_alloc0()</code></a> and linked together by a
 
440
<em class="parameter"><code>next</code></em> pointer (similar to <a class="link" href="glib-Singly-Linked-Lists.html#GSList" title="GSList"><span class="type">GSList</span></a>). The name of the
485
441
<em class="parameter"><code>next</code></em> field in <em class="parameter"><code>type</code></em> is passed as third argument.
486
442
Note that the exact release behaviour can be changed with the
487
443
<a class="link" href="glib-running.html#G_DEBUG" title="G_DEBUG">G_DEBUG=gc-friendly</a> environment variable,
491
447
<col align="left" valign="top">
492
448
<tbody>
493
449
<tr>
494
 
<td><p><span class="term"><em class="parameter"><code>type</code></em>&#160;:</span></p></td>
 
450
<td><p><span class="term"><em class="parameter"><code>type</code></em> :</span></p></td>
495
451
<td>       the type of the <em class="parameter"><code>mem_chain</code></em> blocks
496
452
</td>
497
453
</tr>
498
454
<tr>
499
 
<td><p><span class="term"><em class="parameter"><code>mem_chain</code></em>&#160;:</span></p></td>
 
455
<td><p><span class="term"><em class="parameter"><code>mem_chain</code></em> :</span></p></td>
500
456
<td>  a pointer to the first block of the chain
501
457
</td>
502
458
</tr>
503
459
<tr>
504
 
<td><p><span class="term"><em class="parameter"><code>next</code></em>&#160;:</span></p></td>
 
460
<td><p><span class="term"><em class="parameter"><code>next</code></em> :</span></p></td>
505
461
<td>       the field name of the next pointer in <em class="parameter"><code>type</code></em>
506
462
</td>
507
463
</tr>
508
464
</tbody>
509
465
</table></div>
510
 
<p class="since">Since 2.10
511
 
 
512
 
 
513
 
</p>
514
 
</div>
515
 
</div>
516
 
<div class="refsect1" lang="en">
517
 
<a name="id3287902"></a><div class="refsect2" lang="en"><a name="id3287903"></a></div>
518
 
<hr>
519
 
<div class="refsect2" lang="en"><a name="id3287904"></a></div>
 
466
<p class="since">Since 2.10</p>
 
467
</div>
520
468
</div>
521
469
<div class="footnotes">
522
470
<br><hr width="100" align="left">
523
 
<div class="footnote"><p><sup>[<a name="ftn.id3286464" href="#id3286464" class="para">6</a>] </sup>
 
471
<div class="footnote"><p><sup>[<a name="ftn.id3337918" href="#id3337918" class="para">6</a>] </sup>
524
472
<a class="ulink" href="http://citeseer.ist.psu.edu/bonwick94slab.html" target="_top">[Bonwick94]</a> Jeff Bonwick, The slab allocator: An object-caching kernel
525
 
memory allocator. USENIX 1994, and  
 
473
memory allocator. USENIX 1994, and
526
474
<a class="ulink" href="http://citeseer.ist.psu.edu/bonwick01magazines.html" target="_top">[Bonwick01]</a> Bonwick and Jonathan Adams, Magazines and vmem: Extending the
527
475
slab allocator to many cpu's and arbitrary resources. USENIX 2001
528
476
</p></div>
529
477
</div>
530
478
</div>
 
479
<div class="footer">
 
480
<hr>
 
481
          Generated by GTK-Doc V1.11</div>
531
482
</body>
532
483
</html>