1
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
4
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
5
<title>Memory Allocators</title>
6
<meta name="generator" content="DocBook XSL Stylesheets V1.72.0">
7
<link rel="start" 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-Caches.html" title="Caches">
10
<link rel="next" href="tools.html" title="GLib Tools">
11
<meta name="generator" content="GTK-Doc V1.7 (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="ix01.html" title="Index">
20
<link rel="index" href="ix02.html" title="Index of deprecated symbols">
21
<link rel="index" href="ix03.html" title="Index of new symbols in 2.2">
22
<link rel="index" href="ix04.html" title="Index of new symbols in 2.4">
23
<link rel="index" href="ix05.html" title="Index of new symbols in 2.6">
24
<link rel="index" href="ix06.html" title="Index of new symbols in 2.8">
25
<link rel="index" href="ix07.html" title="Index of new symbols in 2.10">
26
<link rel="index" href="ix08.html" title="Index of new symbols in 2.12">
28
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
29
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2">
31
<td><a accesskey="p" href="glib-Caches.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
32
<td><a accesskey="u" href="glib-data-types.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
33
<td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
34
<th width="100%" align="center">GLib Reference Manual</th>
35
<td><a accesskey="n" href="tools.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
37
<tr><td colspan="5" class="shortcuts"><nobr><a href="#id3155822" class="shortcut">Top</a>
39
<a href="#id3155920" class="shortcut">Description</a></nobr></td></tr>
41
<div class="refentry" lang="en">
42
<a name="glib-Memory-Allocators"></a><div class="titlepage"></div>
43
<div class="refnamediv"><table width="100%"><tr>
46
<a name="id3155822"></a><span class="refentrytitle">Memory Allocators</span>
48
<p>Memory Allocators — deprecated way to allocate chunks of memory for <a href="glib-Doubly-Linked-Lists.html#GList"><span class="type">GList</span></a>, <a href="glib-Singly-Linked-Lists.html#GSList"><span class="type">GSList</span></a> and <a href="glib-N-ary-Trees.html#GNode"><span class="type">GNode</span></a>.</p>
50
<td valign="top" align="right"></td>
52
<div class="refsynopsisdiv">
54
<pre class="synopsis">
56
#include <glib.h>
59
<a href="glib-Memory-Allocators.html#GAllocator">GAllocator</a>;
60
<a href="glib-Memory-Allocators.html#GAllocator">GAllocator</a>* <a href="glib-Memory-Allocators.html#g-allocator-new">g_allocator_new</a> (const <a href="glib-Basic-Types.html#gchar">gchar</a> *name,
61
<a href="glib-Basic-Types.html#guint">guint</a> n_preallocs);
62
void <a href="glib-Memory-Allocators.html#g-allocator-free">g_allocator_free</a> (<a href="glib-Memory-Allocators.html#GAllocator">GAllocator</a> *allocator);
66
<div class="refsect1" lang="en">
67
<a name="id3155920"></a><h2>Description</h2>
71
Prior to 2.10, <a href="glib-Memory-Allocators.html#GAllocator"><span class="type">GAllocator</span></a> was used as an efficient way to allocate
72
small pieces of memory for use with the <a href="glib-Doubly-Linked-Lists.html#GList"><span class="type">GList</span></a>, <a href="glib-Singly-Linked-Lists.html#GSList"><span class="type">GSList</span></a> and <a href="glib-N-ary-Trees.html#GNode"><span class="type">GNode</span></a> data
73
structures. Since 2.10, it has been completely replaced by the
74
<a href="glib-Memory-Slices.html" title="Memory Slices">slice allocator</a> and deprecated.
77
<div class="refsect1" lang="en">
78
<a name="id3155979"></a><h2>Details</h2>
79
<div class="refsect2" lang="en">
80
<a name="id3155989"></a><h3>
81
<a name="GAllocator"></a>GAllocator</h3>
82
<a class="indexterm" name="id3156004"></a><pre class="programlisting">typedef struct _GAllocator GAllocator;</pre>
83
<div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;">
84
<h3 class="title">Warning</h3>
85
<p><code class="literal">GAllocator</code> is deprecated and should not be used in newly-written code.</p>
88
The <span class="structname">GAllocator</span> struct contains private data. and
89
should only be accessed using the following functions.
93
<div class="refsect2" lang="en">
94
<a name="id3156037"></a><h3>
95
<a name="g-allocator-new"></a>g_allocator_new ()</h3>
96
<a class="indexterm" name="id3156052"></a><pre class="programlisting"><a href="glib-Memory-Allocators.html#GAllocator">GAllocator</a>* g_allocator_new (const <a href="glib-Basic-Types.html#gchar">gchar</a> *name,
97
<a href="glib-Basic-Types.html#guint">guint</a> n_preallocs);</pre>
98
<div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;">
99
<h3 class="title">Warning</h3>
100
<p><code class="literal">g_allocator_new</code> has been deprecated since version 2.10 and should not be used in newly-written code. Use the <a href="glib-Memory-Slices.html" title="Memory Slices">slice allocator</a>
104
Creates a new <a href="glib-Memory-Allocators.html#GAllocator"><span class="type">GAllocator</span></a>.
106
<div class="variablelist"><table border="0">
107
<col align="left" valign="top">
110
<td><span class="term"><em class="parameter"><code>name</code></em> :</span></td>
111
<td>the name of the <a href="glib-Memory-Allocators.html#GAllocator"><span class="type">GAllocator</span></a>. This name is used to set the name of the
112
<a href="glib-Memory-Chunks.html#GMemChunk"><span class="type">GMemChunk</span></a> used by the <a href="glib-Memory-Allocators.html#GAllocator"><span class="type">GAllocator</span></a>, and is only used for debugging.
116
<td><span class="term"><em class="parameter"><code>n_preallocs</code></em> :</span></td>
117
<td>the number of elements in each block of memory allocated.
118
Larger blocks mean less calls to <a href="glib-Memory-Allocation.html#g-malloc"><code class="function">g_malloc()</code></a>, but some memory may be wasted.
119
(GLib uses 128 elements per block by default.) The value must be between 1
124
<td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td>
125
<td>a new <a href="glib-Memory-Allocators.html#GAllocator"><span class="type">GAllocator</span></a>.
132
<div class="refsect2" lang="en">
133
<a name="id3156205"></a><h3>
134
<a name="g-allocator-free"></a>g_allocator_free ()</h3>
135
<a class="indexterm" name="id3156220"></a><pre class="programlisting">void g_allocator_free (<a href="glib-Memory-Allocators.html#GAllocator">GAllocator</a> *allocator);</pre>
136
<div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;">
137
<h3 class="title">Warning</h3>
138
<p><code class="literal">g_allocator_free</code> has been deprecated since version 2.10 and should not be used in newly-written code. Use the <a href="glib-Memory-Slices.html" title="Memory Slices">slice allocator</a>
142
Frees all of the memory allocated by the <a href="glib-Memory-Allocators.html#GAllocator"><span class="type">GAllocator</span></a>.
144
<div class="variablelist"><table border="0">
145
<col align="left" valign="top">
147
<td><span class="term"><em class="parameter"><code>allocator</code></em> :</span></td>
148
<td>a <a href="glib-Memory-Allocators.html#GAllocator"><span class="type">GAllocator</span></a>.