33
30
<h2><span class="refentrytitle"><a name="libvips-memory.top_of_page"></a>memory</span></h2>
34
31
<p>memory — memory utilities</p>
36
<td valign="top" align="right"></td>
33
<td class="gallery_image" valign="top" align="right"></td>
37
34
</tr></table></div>
38
35
<div class="refsect1">
39
36
<a name="libvips-memory.stability-level"></a><h2>Stability Level</h2>
40
37
Stable, unless otherwise indicated
42
<div class="refsynopsisdiv">
43
<a name="libvips-memory.synopsis"></a><h2>Synopsis</h2>
44
<pre class="synopsis">
45
#include <vips/vips.h>
47
#define <a class="link" href="libvips-memory.html#VIPS-FREEF:CAPS" title="VIPS_FREEF()">VIPS_FREEF</a> (F,
49
#define <a class="link" href="libvips-memory.html#VIPS-FREE:CAPS" title="VIPS_FREE()">VIPS_FREE</a> (S)
50
#define <a class="link" href="libvips-memory.html#VIPS-SETSTR:CAPS" title="VIPS_SETSTR()">VIPS_SETSTR</a> (S,
52
#define <a class="link" href="libvips-memory.html#VIPS-NEW:CAPS" title="VIPS_NEW()">VIPS_NEW</a> (OBJ,
54
#define <a class="link" href="libvips-memory.html#VIPS-ARRAY:CAPS" title="VIPS_ARRAY()">VIPS_ARRAY</a> (OBJ,
57
<span class="returnvalue">void</span> * <a class="link" href="libvips-memory.html#vips-malloc" title="vips_malloc ()">vips_malloc</a> (<em class="parameter"><code><a class="link" href="libvips-VipsArgument.html#VipsObject"><span class="type">VipsObject</span></a> *object</code></em>,
58
<em class="parameter"><code><span class="type">size_t</span> size</code></em>);
59
<span class="returnvalue">char</span> * <a class="link" href="libvips-memory.html#vips-strdup" title="vips_strdup ()">vips_strdup</a> (<em class="parameter"><code><a class="link" href="libvips-VipsArgument.html#VipsObject"><span class="type">VipsObject</span></a> *object</code></em>,
60
<em class="parameter"><code>const <span class="type">char</span> *str</code></em>);
61
<span class="returnvalue">int</span> <a class="link" href="libvips-memory.html#vips-free" title="vips_free ()">vips_free</a> (<em class="parameter"><code><span class="type">void</span> *buf</code></em>);
62
<span class="returnvalue">void</span> <a class="link" href="libvips-memory.html#vips-tracked-free" title="vips_tracked_free ()">vips_tracked_free</a> (<em class="parameter"><code><span class="type">void</span> *s</code></em>);
63
<span class="returnvalue">void</span> * <a class="link" href="libvips-memory.html#vips-tracked-malloc" title="vips_tracked_malloc ()">vips_tracked_malloc</a> (<em class="parameter"><code><span class="type">size_t</span> size</code></em>);
64
<span class="returnvalue">size_t</span> <a class="link" href="libvips-memory.html#vips-tracked-get-mem" title="vips_tracked_get_mem ()">vips_tracked_get_mem</a> (<em class="parameter"><code><span class="type">void</span></code></em>);
65
<span class="returnvalue">size_t</span> <a class="link" href="libvips-memory.html#vips-tracked-get-mem-highwater" title="vips_tracked_get_mem_highwater ()">vips_tracked_get_mem_highwater</a> (<em class="parameter"><code><span class="type">void</span></code></em>);
66
<span class="returnvalue">int</span> <a class="link" href="libvips-memory.html#vips-tracked-get-allocs" title="vips_tracked_get_allocs ()">vips_tracked_get_allocs</a> (<em class="parameter"><code><span class="type">void</span></code></em>);
67
<span class="returnvalue">int</span> <a class="link" href="libvips-memory.html#vips-tracked-open" title="vips_tracked_open ()">vips_tracked_open</a> (<em class="parameter"><code>const <span class="type">char</span> *pathname</code></em>,
68
<em class="parameter"><code><span class="type">int</span> flags</code></em>,
69
<em class="parameter"><code>...</code></em>);
70
<span class="returnvalue">int</span> <a class="link" href="libvips-memory.html#vips-tracked-close" title="vips_tracked_close ()">vips_tracked_close</a> (<em class="parameter"><code><span class="type">int</span> fd</code></em>);
71
<span class="returnvalue">int</span> <a class="link" href="libvips-memory.html#vips-tracked-get-files" title="vips_tracked_get_files ()">vips_tracked_get_files</a> (<em class="parameter"><code><span class="type">void</span></code></em>);
39
<div class="refsect1">
40
<a name="libvips-memory.functions"></a><h2>Functions</h2>
41
<div class="informaltable"><table width="100%" border="0">
43
<col width="150px" class="functions_return">
44
<col class="functions_name">
48
<td class="define_keyword">#define</td>
49
<td class="function_name">
50
<a class="link" href="libvips-memory.html#VIPS-FREEF:CAPS" title="VIPS_FREEF()">VIPS_FREEF</a><span class="c_punctuation">()</span>
54
<td class="define_keyword">#define</td>
55
<td class="function_name">
56
<a class="link" href="libvips-memory.html#VIPS-FREE:CAPS" title="VIPS_FREE()">VIPS_FREE</a><span class="c_punctuation">()</span>
60
<td class="define_keyword">#define</td>
61
<td class="function_name">
62
<a class="link" href="libvips-memory.html#VIPS-SETSTR:CAPS" title="VIPS_SETSTR()">VIPS_SETSTR</a><span class="c_punctuation">()</span>
66
<td class="define_keyword">#define</td>
67
<td class="function_name">
68
<a class="link" href="libvips-memory.html#VIPS-NEW:CAPS" title="VIPS_NEW()">VIPS_NEW</a><span class="c_punctuation">()</span>
72
<td class="define_keyword">#define</td>
73
<td class="function_name">
74
<a class="link" href="libvips-memory.html#VIPS-ARRAY:CAPS" title="VIPS_ARRAY()">VIPS_ARRAY</a><span class="c_punctuation">()</span>
78
<td class="function_type">
79
<span class="returnvalue">void</span> *
81
<td class="function_name">
82
<a class="link" href="libvips-memory.html#vips-malloc" title="vips_malloc ()">vips_malloc</a> <span class="c_punctuation">()</span>
86
<td class="function_type">
87
<span class="returnvalue">char</span> *
89
<td class="function_name">
90
<a class="link" href="libvips-memory.html#vips-strdup" title="vips_strdup ()">vips_strdup</a> <span class="c_punctuation">()</span>
94
<td class="function_type">
95
<span class="returnvalue">int</span>
97
<td class="function_name">
98
<a class="link" href="libvips-memory.html#vips-free" title="vips_free ()">vips_free</a> <span class="c_punctuation">()</span>
102
<td class="function_type">
103
<span class="returnvalue">void</span>
105
<td class="function_name">
106
<a class="link" href="libvips-memory.html#vips-tracked-free" title="vips_tracked_free ()">vips_tracked_free</a> <span class="c_punctuation">()</span>
110
<td class="function_type">
111
<span class="returnvalue">void</span> *
113
<td class="function_name">
114
<a class="link" href="libvips-memory.html#vips-tracked-malloc" title="vips_tracked_malloc ()">vips_tracked_malloc</a> <span class="c_punctuation">()</span>
118
<td class="function_type">
119
<span class="returnvalue">size_t</span>
121
<td class="function_name">
122
<a class="link" href="libvips-memory.html#vips-tracked-get-mem" title="vips_tracked_get_mem ()">vips_tracked_get_mem</a> <span class="c_punctuation">()</span>
126
<td class="function_type">
127
<span class="returnvalue">size_t</span>
129
<td class="function_name">
130
<a class="link" href="libvips-memory.html#vips-tracked-get-mem-highwater" title="vips_tracked_get_mem_highwater ()">vips_tracked_get_mem_highwater</a> <span class="c_punctuation">()</span>
134
<td class="function_type">
135
<span class="returnvalue">int</span>
137
<td class="function_name">
138
<a class="link" href="libvips-memory.html#vips-tracked-get-allocs" title="vips_tracked_get_allocs ()">vips_tracked_get_allocs</a> <span class="c_punctuation">()</span>
142
<td class="function_type">
143
<span class="returnvalue">int</span>
145
<td class="function_name">
146
<a class="link" href="libvips-memory.html#vips-tracked-open" title="vips_tracked_open ()">vips_tracked_open</a> <span class="c_punctuation">()</span>
150
<td class="function_type">
151
<span class="returnvalue">int</span>
153
<td class="function_name">
154
<a class="link" href="libvips-memory.html#vips-tracked-close" title="vips_tracked_close ()">vips_tracked_close</a> <span class="c_punctuation">()</span>
158
<td class="function_type">
159
<span class="returnvalue">int</span>
161
<td class="function_name">
162
<a class="link" href="libvips-memory.html#vips-tracked-get-files" title="vips_tracked_get_files ()">vips_tracked_get_files</a> <span class="c_punctuation">()</span>
168
<div class="refsect1">
169
<a name="libvips-memory.object-hierarchy"></a><h2>Object Hierarchy</h2>
173
<div class="refsect1">
174
<a name="libvips-memory.includes"></a><h2>Includes</h2>
175
<pre class="synopsis">#include <vips/vips.h>
74
178
<div class="refsect1">
75
179
<a name="libvips-memory.description"></a><h2>Description</h2>
77
These functions cover two main areas.
80
First, some simple utility functions over the underlying
81
<code class="function">g_malloc()</code>/<code class="function">g_free()</code> functions. Memory allocated and freeded using these
82
functions is interchangeable with any other glib library.
85
Second, a pair of functions, <a class="link" href="libvips-memory.html#vips-tracked-malloc" title="vips_tracked_malloc ()"><code class="function">vips_tracked_malloc()</code></a> and <a class="link" href="libvips-memory.html#vips-tracked-free" title="vips_tracked_free ()"><code class="function">vips_tracked_free()</code></a>,
86
which are NOT compatible. If you <code class="function">g_free()</code> memory that has been allocated
87
with <a class="link" href="libvips-memory.html#vips-tracked-malloc" title="vips_tracked_malloc ()"><code class="function">vips_tracked_malloc()</code></a> you will see crashes.
90
The tracked functions are
180
<p>These functions cover two main areas.</p>
181
<p>First, some simple utility functions over the underlying
182
<a href="http://library.gnome.org/devel/glib/unstable/glib-Memory-Allocation.html#g-malloc"><code class="function">g_malloc()</code></a>/<a href="http://library.gnome.org/devel/glib/unstable/glib-Memory-Allocation.html#g-free"><code class="function">g_free()</code></a> functions. Memory allocated and freeded using these
183
functions is interchangeable with any other glib library.</p>
184
<p>Second, a pair of functions, <a class="link" href="libvips-memory.html#vips-tracked-malloc" title="vips_tracked_malloc ()"><code class="function">vips_tracked_malloc()</code></a> and <a class="link" href="libvips-memory.html#vips-tracked-free" title="vips_tracked_free ()"><code class="function">vips_tracked_free()</code></a>,
185
which are NOT compatible. If you <a href="http://library.gnome.org/devel/glib/unstable/glib-Memory-Allocation.html#g-free"><code class="function">g_free()</code></a> memory that has been allocated
186
with <a class="link" href="libvips-memory.html#vips-tracked-malloc" title="vips_tracked_malloc ()"><code class="function">vips_tracked_malloc()</code></a> you will see crashes. </p>
187
<p>The tracked functions are
91
188
only suitable for large allocations internal to the library, for example
92
189
pixel buffers. libvips watches the total amount of live tracked memory and
93
uses this information to decide when to trim caches.
190
uses this information to decide when to trim caches.</p>
96
192
<div class="refsect1">
97
<a name="libvips-memory.details"></a><h2>Details</h2>
193
<a name="libvips-memory.functions_details"></a><h2>Functions</h2>
98
194
<div class="refsect2">
99
195
<a name="VIPS-FREEF:CAPS"></a><h3>VIPS_FREEF()</h3>
100
196
<pre class="programlisting">#define VIPS_FREEF( F, S )</pre>
120
216
<div class="refsect2">
121
217
<a name="VIPS-NEW:CAPS"></a><h3>VIPS_NEW()</h3>
122
218
<pre class="programlisting">#define VIPS_NEW( OBJ, T )</pre>
123
<div class="variablelist"><table border="0" class="variablelist">
219
<div class="refsect3">
220
<a name="id-1.2.10.8.5.4"></a><h4>Parameters</h4>
221
<div class="informaltable"><table width="100%" border="0">
125
<col align="left" valign="top">
223
<col width="150px" class="parameters_name">
224
<col class="parameters_description">
225
<col width="200px" class="parameters_annotations">
130
<td><p><span class="term"><em class="parameter"><code>OBJ</code></em> :</span></p></td>
131
<td>allocate memory local to <em class="parameter"><code>OBJ</code></em>, or <code class="literal">NULL</code> for no auto-free</td>
134
<td><p><span class="term"><em class="parameter"><code>T</code></em> :</span></p></td>
135
<td>type of thing to allocate</td>
138
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
139
<td>A pointer of type <em class="parameter"><code>T</code></em> *, or <code class="literal">NULL</code> on error.</td>
229
<td class="parameter_name"><p>OBJ</p></td>
230
<td class="parameter_description"><p>allocate memory local to <em class="parameter"><code>OBJ</code></em>
231
, or <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> for no auto-free</p></td>
232
<td class="parameter_annotations"> </td>
235
<td class="parameter_name"><p>T</p></td>
236
<td class="parameter_description"><p>type of thing to allocate</p></td>
237
<td class="parameter_annotations"> </td>
242
<div class="refsect3">
243
<a name="id-1.2.10.8.5.5"></a><h4>Returns</h4>
244
<p> A pointer of type <em class="parameter"><code>T</code></em>
245
*, or <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> on error.</p>
145
250
<div class="refsect2">
146
251
<a name="VIPS-ARRAY:CAPS"></a><h3>VIPS_ARRAY()</h3>
147
252
<pre class="programlisting">#define VIPS_ARRAY( OBJ, N, T )</pre>
148
<div class="variablelist"><table border="0" class="variablelist">
150
<col align="left" valign="top">
155
<td><p><span class="term"><em class="parameter"><code>OBJ</code></em> :</span></p></td>
156
<td>allocate memory local to <em class="parameter"><code>OBJ</code></em>, or <code class="literal">NULL</code> for no auto-free</td>
159
<td><p><span class="term"><em class="parameter"><code>N</code></em> :</span></p></td>
160
<td>number of <em class="parameter"><code>T</code></em> 's to allocate</td>
163
<td><p><span class="term"><em class="parameter"><code>T</code></em> :</span></p></td>
164
<td>type of thing to allocate</td>
167
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
168
<td>A pointer of type <em class="parameter"><code>T</code></em> *, or <code class="literal">NULL</code> on error.</td>
174
<div class="refsect2">
175
<a name="vips-malloc"></a><h3>vips_malloc ()</h3>
176
<pre class="programlisting"><span class="returnvalue">void</span> * vips_malloc (<em class="parameter"><code><a class="link" href="libvips-VipsArgument.html#VipsObject"><span class="type">VipsObject</span></a> *object</code></em>,
177
<em class="parameter"><code><span class="type">size_t</span> size</code></em>);</pre>
179
<code class="function">g_malloc()</code> local to <em class="parameter"><code>object</code></em>, that is, the memory will be automatically
180
freed for you when the object is closed. If <em class="parameter"><code>object</code></em> is <code class="literal">NULL</code>, you need to
181
free the memory explicitly with <code class="function">g_free()</code>.
184
This function cannot fail. See <a class="link" href="libvips-memory.html#vips-tracked-malloc" title="vips_tracked_malloc ()"><code class="function">vips_tracked_malloc()</code></a> if you are
185
allocating large amounts of memory.
188
See also: <a class="link" href="libvips-memory.html#vips-tracked-malloc" title="vips_tracked_malloc ()"><code class="function">vips_tracked_malloc()</code></a>.
190
<div class="variablelist"><table border="0" class="variablelist">
192
<col align="left" valign="top">
197
<td><p><span class="term"><em class="parameter"><code>object</code></em> :</span></p></td>
198
<td>allocate memory local to this <a class="link" href="libvips-VipsArgument.html#VipsObject"><span class="type">VipsObject</span></a>, or <code class="literal">NULL</code>
202
<td><p><span class="term"><em class="parameter"><code>size</code></em> :</span></p></td>
203
<td>number of bytes to allocate</td>
206
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
207
<td>a pointer to the allocated memory</td>
213
<div class="refsect2">
214
<a name="vips-strdup"></a><h3>vips_strdup ()</h3>
215
<pre class="programlisting"><span class="returnvalue">char</span> * vips_strdup (<em class="parameter"><code><a class="link" href="libvips-VipsArgument.html#VipsObject"><span class="type">VipsObject</span></a> *object</code></em>,
216
<em class="parameter"><code>const <span class="type">char</span> *str</code></em>);</pre>
218
<code class="function">g_strdup()</code> a string. When <em class="parameter"><code>object</code></em> is freed, the string will be freed for
219
you. If <em class="parameter"><code>object</code></em> is <code class="literal">NULL</code>, you need to
220
free the memory explicitly with <code class="function">g_free()</code>.
223
This function cannot fail.
226
See also: <a class="link" href="libvips-memory.html#vips-malloc" title="vips_malloc ()"><code class="function">vips_malloc()</code></a>.
228
<div class="variablelist"><table border="0" class="variablelist">
230
<col align="left" valign="top">
235
<td><p><span class="term"><em class="parameter"><code>object</code></em> :</span></p></td>
236
<td>allocate memory local to this <a class="link" href="libvips-VipsArgument.html#VipsObject"><span class="type">VipsObject</span></a>, or <code class="literal">NULL</code>
240
<td><p><span class="term"><em class="parameter"><code>str</code></em> :</span></p></td>
241
<td>string to copy</td>
244
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
245
<td>a pointer to the allocated memory</td>
251
<div class="refsect2">
252
<a name="vips-free"></a><h3>vips_free ()</h3>
253
<pre class="programlisting"><span class="returnvalue">int</span> vips_free (<em class="parameter"><code><span class="type">void</span> *buf</code></em>);</pre>
255
Frees memory with <code class="function">g_free()</code> and returns 0. Handy for callbacks.
258
See also: <a class="link" href="libvips-memory.html#vips-malloc" title="vips_malloc ()"><code class="function">vips_malloc()</code></a>.
260
<div class="variablelist"><table border="0" class="variablelist">
262
<col align="left" valign="top">
266
<td><p><span class="term"><em class="parameter"><code>buf</code></em> :</span></p></td>
267
<td>memory to free</td>
272
<div class="refsect2">
273
<a name="vips-tracked-free"></a><h3>vips_tracked_free ()</h3>
274
<pre class="programlisting"><span class="returnvalue">void</span> vips_tracked_free (<em class="parameter"><code><span class="type">void</span> *s</code></em>);</pre>
277
memory that was previously allocated with <a class="link" href="libvips-memory.html#vips-tracked-malloc" title="vips_tracked_malloc ()"><code class="function">vips_tracked_malloc()</code></a> with a
278
<code class="literal">NULL</code> first argument.
281
See also: <a class="link" href="libvips-memory.html#vips-tracked-malloc" title="vips_tracked_malloc ()"><code class="function">vips_tracked_malloc()</code></a>.
283
<div class="variablelist"><table border="0" class="variablelist">
285
<col align="left" valign="top">
289
<td><p><span class="term"><em class="parameter"><code>s</code></em> :</span></p></td>
290
<td>memory to free</td>
295
<div class="refsect2">
296
<a name="vips-tracked-malloc"></a><h3>vips_tracked_malloc ()</h3>
297
<pre class="programlisting"><span class="returnvalue">void</span> * vips_tracked_malloc (<em class="parameter"><code><span class="type">size_t</span> size</code></em>);</pre>
299
Allocate an area of memory that will be tracked by <a class="link" href="libvips-memory.html#vips-tracked-get-mem" title="vips_tracked_get_mem ()"><code class="function">vips_tracked_get_mem()</code></a>
303
If allocation fails, <a class="link" href="libvips-memory.html#vips-malloc" title="vips_malloc ()"><code class="function">vips_malloc()</code></a> returns <code class="literal">NULL</code> and
304
sets an error message.
307
You must only free the memory returned with <a class="link" href="libvips-memory.html#vips-tracked-free" title="vips_tracked_free ()"><code class="function">vips_tracked_free()</code></a>.
310
See also: <a class="link" href="libvips-memory.html#vips-tracked-free" title="vips_tracked_free ()"><code class="function">vips_tracked_free()</code></a>, <a class="link" href="libvips-memory.html#vips-malloc" title="vips_malloc ()"><code class="function">vips_malloc()</code></a>.
312
<div class="variablelist"><table border="0" class="variablelist">
314
<col align="left" valign="top">
319
<td><p><span class="term"><em class="parameter"><code>size</code></em> :</span></p></td>
320
<td>number of bytes to allocate</td>
323
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
324
<td>a pointer to the allocated memory, or <code class="literal">NULL</code> on error.</td>
330
<div class="refsect2">
331
<a name="vips-tracked-get-mem"></a><h3>vips_tracked_get_mem ()</h3>
332
<pre class="programlisting"><span class="returnvalue">size_t</span> vips_tracked_get_mem (<em class="parameter"><code><span class="type">void</span></code></em>);</pre>
334
Returns the number of bytes currently allocated via <a class="link" href="libvips-memory.html#vips-malloc" title="vips_malloc ()"><code class="function">vips_malloc()</code></a> and
253
<div class="refsect3">
254
<a name="id-1.2.10.8.6.4"></a><h4>Parameters</h4>
255
<div class="informaltable"><table width="100%" border="0">
257
<col width="150px" class="parameters_name">
258
<col class="parameters_description">
259
<col width="200px" class="parameters_annotations">
263
<td class="parameter_name"><p>OBJ</p></td>
264
<td class="parameter_description"><p>allocate memory local to <em class="parameter"><code>OBJ</code></em>
265
, or <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> for no auto-free</p></td>
266
<td class="parameter_annotations"> </td>
269
<td class="parameter_name"><p>N</p></td>
270
<td class="parameter_description"><p>number of <em class="parameter"><code>T</code></em>
271
's to allocate</p></td>
272
<td class="parameter_annotations"> </td>
275
<td class="parameter_name"><p>T</p></td>
276
<td class="parameter_description"><p>type of thing to allocate</p></td>
277
<td class="parameter_annotations"> </td>
282
<div class="refsect3">
283
<a name="id-1.2.10.8.6.5"></a><h4>Returns</h4>
284
<p> A pointer of type <em class="parameter"><code>T</code></em>
285
*, or <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> on error.</p>
290
<div class="refsect2">
291
<a name="vips-malloc"></a><h3>vips_malloc ()</h3>
292
<pre class="programlisting"><span class="returnvalue">void</span> *
293
vips_malloc (<em class="parameter"><code><a class="link" href="VipsObject.html" title="VipsObject"><span class="type">VipsObject</span></a> *object</code></em>,
294
<em class="parameter"><code><span class="type">size_t</span> size</code></em>);</pre>
295
<p>g_malloc() local to <em class="parameter"><code>object</code></em>
296
, that is, the memory will be automatically
297
freed for you when the object is closed. If <em class="parameter"><code>object</code></em>
298
is <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>, you need to
299
free the memory explicitly with <a href="http://library.gnome.org/devel/glib/unstable/glib-Memory-Allocation.html#g-free"><code class="function">g_free()</code></a>.</p>
300
<p>This function cannot fail. See <a class="link" href="libvips-memory.html#vips-tracked-malloc" title="vips_tracked_malloc ()"><code class="function">vips_tracked_malloc()</code></a> if you are
301
allocating large amounts of memory.</p>
302
<p>See also: <a class="link" href="libvips-memory.html#vips-tracked-malloc" title="vips_tracked_malloc ()"><code class="function">vips_tracked_malloc()</code></a>.</p>
303
<div class="refsect3">
304
<a name="id-1.2.10.8.7.7"></a><h4>Parameters</h4>
305
<div class="informaltable"><table width="100%" border="0">
307
<col width="150px" class="parameters_name">
308
<col class="parameters_description">
309
<col width="200px" class="parameters_annotations">
313
<td class="parameter_name"><p>object</p></td>
314
<td class="parameter_description"><p>allocate memory local to this <a class="link" href="VipsObject.html" title="VipsObject"><span class="type">VipsObject</span></a>, or <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a></p></td>
315
<td class="parameter_annotations"> </td>
318
<td class="parameter_name"><p>size</p></td>
319
<td class="parameter_description"><p>number of bytes to allocate</p></td>
320
<td class="parameter_annotations"> </td>
325
<div class="refsect3">
326
<a name="id-1.2.10.8.7.8"></a><h4>Returns</h4>
327
<p> a pointer to the allocated memory</p>
332
<div class="refsect2">
333
<a name="vips-strdup"></a><h3>vips_strdup ()</h3>
334
<pre class="programlisting"><span class="returnvalue">char</span> *
335
vips_strdup (<em class="parameter"><code><a class="link" href="VipsObject.html" title="VipsObject"><span class="type">VipsObject</span></a> *object</code></em>,
336
<em class="parameter"><code>const <span class="type">char</span> *str</code></em>);</pre>
337
<p>g_strdup() a string. When <em class="parameter"><code>object</code></em>
338
is freed, the string will be freed for
339
you. If <em class="parameter"><code>object</code></em>
340
is <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>, you need to
341
free the memory explicitly with <a href="http://library.gnome.org/devel/glib/unstable/glib-Memory-Allocation.html#g-free"><code class="function">g_free()</code></a>.</p>
342
<p>This function cannot fail. </p>
343
<p>See also: <a class="link" href="libvips-memory.html#vips-malloc" title="vips_malloc ()"><code class="function">vips_malloc()</code></a>.</p>
344
<div class="refsect3">
345
<a name="id-1.2.10.8.8.7"></a><h4>Parameters</h4>
346
<div class="informaltable"><table width="100%" border="0">
348
<col width="150px" class="parameters_name">
349
<col class="parameters_description">
350
<col width="200px" class="parameters_annotations">
354
<td class="parameter_name"><p>object</p></td>
355
<td class="parameter_description"><p>allocate memory local to this <a class="link" href="VipsObject.html" title="VipsObject"><span class="type">VipsObject</span></a>, or <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a></p></td>
356
<td class="parameter_annotations"> </td>
359
<td class="parameter_name"><p>str</p></td>
360
<td class="parameter_description"><p>string to copy</p></td>
361
<td class="parameter_annotations"> </td>
366
<div class="refsect3">
367
<a name="id-1.2.10.8.8.8"></a><h4>Returns</h4>
368
<p> a pointer to the allocated memory</p>
373
<div class="refsect2">
374
<a name="vips-free"></a><h3>vips_free ()</h3>
375
<pre class="programlisting"><span class="returnvalue">int</span>
376
vips_free (<em class="parameter"><code><span class="type">void</span> *buf</code></em>);</pre>
377
<p>Frees memory with <a href="http://library.gnome.org/devel/glib/unstable/glib-Memory-Allocation.html#g-free"><code class="function">g_free()</code></a> and returns 0. Handy for callbacks.</p>
378
<p>See also: <a class="link" href="libvips-memory.html#vips-malloc" title="vips_malloc ()"><code class="function">vips_malloc()</code></a>.</p>
379
<div class="refsect3">
380
<a name="id-1.2.10.8.9.6"></a><h4>Parameters</h4>
381
<div class="informaltable"><table width="100%" border="0">
383
<col width="150px" class="parameters_name">
384
<col class="parameters_description">
385
<col width="200px" class="parameters_annotations">
388
<td class="parameter_name"><p>buf</p></td>
389
<td class="parameter_description"><p>memory to free</p></td>
390
<td class="parameter_annotations"> </td>
394
<div class="refsect3">
395
<a name="id-1.2.10.8.9.7"></a><h4>Returns</h4>
401
<div class="refsect2">
402
<a name="vips-tracked-free"></a><h3>vips_tracked_free ()</h3>
403
<pre class="programlisting"><span class="returnvalue">void</span>
404
vips_tracked_free (<em class="parameter"><code><span class="type">void</span> *s</code></em>);</pre>
405
<p>Only use it to free
406
memory that was previously allocated with <a class="link" href="libvips-memory.html#vips-tracked-malloc" title="vips_tracked_malloc ()"><code class="function">vips_tracked_malloc()</code></a> with a
407
<a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> first argument.</p>
408
<p>See also: <a class="link" href="libvips-memory.html#vips-tracked-malloc" title="vips_tracked_malloc ()"><code class="function">vips_tracked_malloc()</code></a>.</p>
409
<div class="refsect3">
410
<a name="id-1.2.10.8.10.6"></a><h4>Parameters</h4>
411
<div class="informaltable"><table width="100%" border="0">
413
<col width="150px" class="parameters_name">
414
<col class="parameters_description">
415
<col width="200px" class="parameters_annotations">
418
<td class="parameter_name"><p>s</p></td>
419
<td class="parameter_description"><p>memory to free</p></td>
420
<td class="parameter_annotations"> </td>
426
<div class="refsect2">
427
<a name="vips-tracked-malloc"></a><h3>vips_tracked_malloc ()</h3>
428
<pre class="programlisting"><span class="returnvalue">void</span> *
429
vips_tracked_malloc (<em class="parameter"><code><span class="type">size_t</span> size</code></em>);</pre>
430
<p>Allocate an area of memory that will be tracked by <a class="link" href="libvips-memory.html#vips-tracked-get-mem" title="vips_tracked_get_mem ()"><code class="function">vips_tracked_get_mem()</code></a>
432
<p>If allocation fails, <a class="link" href="libvips-memory.html#vips-malloc" title="vips_malloc ()"><code class="function">vips_malloc()</code></a> returns <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> and
433
sets an error message.</p>
434
<p>You must only free the memory returned with <a class="link" href="libvips-memory.html#vips-tracked-free" title="vips_tracked_free ()"><code class="function">vips_tracked_free()</code></a>.</p>
435
<p>See also: <a class="link" href="libvips-memory.html#vips-tracked-free" title="vips_tracked_free ()"><code class="function">vips_tracked_free()</code></a>, <a class="link" href="libvips-memory.html#vips-malloc" title="vips_malloc ()"><code class="function">vips_malloc()</code></a>.</p>
436
<div class="refsect3">
437
<a name="id-1.2.10.8.11.8"></a><h4>Parameters</h4>
438
<div class="informaltable"><table width="100%" border="0">
440
<col width="150px" class="parameters_name">
441
<col class="parameters_description">
442
<col width="200px" class="parameters_annotations">
445
<td class="parameter_name"><p>size</p></td>
446
<td class="parameter_description"><p>number of bytes to allocate</p></td>
447
<td class="parameter_annotations"> </td>
451
<div class="refsect3">
452
<a name="id-1.2.10.8.11.9"></a><h4>Returns</h4>
453
<p> a pointer to the allocated memory, or <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> on error.</p>
458
<div class="refsect2">
459
<a name="vips-tracked-get-mem"></a><h3>vips_tracked_get_mem ()</h3>
460
<pre class="programlisting"><span class="returnvalue">size_t</span>
461
vips_tracked_get_mem (<em class="parameter"><code><span class="type">void</span></code></em>);</pre>
462
<p>Returns the number of bytes currently allocated via <a class="link" href="libvips-memory.html#vips-malloc" title="vips_malloc ()"><code class="function">vips_malloc()</code></a> and
335
463
friends. vips uses this figure to decide when to start dropping cache, see
336
<a class="link" href="VipsOperation.html" title="VipsOperation"><span class="type">VipsOperation</span></a>.
338
<div class="variablelist"><table border="0" class="variablelist">
340
<col align="left" valign="top">
344
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
345
<td>the number of currently allocated bytes</td>
350
<div class="refsect2">
351
<a name="vips-tracked-get-mem-highwater"></a><h3>vips_tracked_get_mem_highwater ()</h3>
352
<pre class="programlisting"><span class="returnvalue">size_t</span> vips_tracked_get_mem_highwater (<em class="parameter"><code><span class="type">void</span></code></em>);</pre>
354
Returns the largest number of bytes simultaneously allocated via
355
<a class="link" href="libvips-memory.html#vips-tracked-malloc" title="vips_tracked_malloc ()"><code class="function">vips_tracked_malloc()</code></a>. Handy for estimating max memory requirements for a
358
<div class="variablelist"><table border="0" class="variablelist">
360
<col align="left" valign="top">
364
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
365
<td>the largest number of currently allocated bytes</td>
370
<div class="refsect2">
371
<a name="vips-tracked-get-allocs"></a><h3>vips_tracked_get_allocs ()</h3>
372
<pre class="programlisting"><span class="returnvalue">int</span> vips_tracked_get_allocs (<em class="parameter"><code><span class="type">void</span></code></em>);</pre>
374
Returns the number of active allocations.
376
<div class="variablelist"><table border="0" class="variablelist">
378
<col align="left" valign="top">
382
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
383
<td>the number of active allocations</td>
388
<div class="refsect2">
389
<a name="vips-tracked-open"></a><h3>vips_tracked_open ()</h3>
390
<pre class="programlisting"><span class="returnvalue">int</span> vips_tracked_open (<em class="parameter"><code>const <span class="type">char</span> *pathname</code></em>,
391
<em class="parameter"><code><span class="type">int</span> flags</code></em>,
392
<em class="parameter"><code>...</code></em>);</pre>
394
Exactly as open(2), but the number of files current open via
395
<a class="link" href="libvips-memory.html#vips-tracked-open" title="vips_tracked_open ()"><code class="function">vips_tracked_open()</code></a> is available via <a class="link" href="libvips-memory.html#vips-tracked-get-files" title="vips_tracked_get_files ()"><code class="function">vips_tracked_get_files()</code></a>. This is used
396
by the vips operation cache to drop cache when the number of files
400
You must only close the file descriptor with <a class="link" href="libvips-memory.html#vips-tracked-close" title="vips_tracked_close ()"><code class="function">vips_tracked_close()</code></a>.
403
See also: <a class="link" href="libvips-memory.html#vips-tracked-close" title="vips_tracked_close ()"><code class="function">vips_tracked_close()</code></a>, <a class="link" href="libvips-memory.html#vips-tracked-get-files" title="vips_tracked_get_files ()"><code class="function">vips_tracked_get_files()</code></a>.
405
<div class="variablelist"><table border="0" class="variablelist">
407
<col align="left" valign="top">
412
<td><p><span class="term"><em class="parameter"><code>pathname</code></em> :</span></p></td>
413
<td>name of file to open</td>
416
<td><p><span class="term"><em class="parameter"><code>flags</code></em> :</span></p></td>
417
<td>flags for <code class="function">open()</code>
421
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
422
<td>a file descriptor, or -1 on error.</td>
428
<div class="refsect2">
429
<a name="vips-tracked-close"></a><h3>vips_tracked_close ()</h3>
430
<pre class="programlisting"><span class="returnvalue">int</span> vips_tracked_close (<em class="parameter"><code><span class="type">int</span> fd</code></em>);</pre>
432
Exactly as close(2), but update the number of files currently open via
433
<a class="link" href="libvips-memory.html#vips-tracked-get-files" title="vips_tracked_get_files ()"><code class="function">vips_tracked_get_files()</code></a>. This is used
434
by the vips operation cache to drop cache when the number of files
438
You must only close file descriptors opened with <a class="link" href="libvips-memory.html#vips-tracked-open" title="vips_tracked_open ()"><code class="function">vips_tracked_open()</code></a>.
441
See also: <a class="link" href="libvips-memory.html#vips-tracked-open" title="vips_tracked_open ()"><code class="function">vips_tracked_open()</code></a>, <a class="link" href="libvips-memory.html#vips-tracked-get-files" title="vips_tracked_get_files ()"><code class="function">vips_tracked_get_files()</code></a>.
443
<div class="variablelist"><table border="0" class="variablelist">
445
<col align="left" valign="top">
450
<td><p><span class="term"><em class="parameter"><code>fd</code></em> :</span></p></td>
451
<td>file to <code class="function">close()</code>
455
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
456
<td>a file descriptor, or -1 on error.</td>
462
<div class="refsect2">
463
<a name="vips-tracked-get-files"></a><h3>vips_tracked_get_files ()</h3>
464
<pre class="programlisting"><span class="returnvalue">int</span> vips_tracked_get_files (<em class="parameter"><code><span class="type">void</span></code></em>);</pre>
466
Returns the number of open files.
468
<div class="variablelist"><table border="0" class="variablelist">
470
<col align="left" valign="top">
474
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
475
<td>the number of open files</td>
464
<a class="link" href="VipsOperation.html" title="VipsOperation"><span class="type">VipsOperation</span></a>.</p>
465
<div class="refsect3">
466
<a name="id-1.2.10.8.12.5"></a><h4>Returns</h4>
467
<p> the number of currently allocated bytes</p>
472
<div class="refsect2">
473
<a name="vips-tracked-get-mem-highwater"></a><h3>vips_tracked_get_mem_highwater ()</h3>
474
<pre class="programlisting"><span class="returnvalue">size_t</span>
475
vips_tracked_get_mem_highwater (<em class="parameter"><code><span class="type">void</span></code></em>);</pre>
476
<p>Returns the largest number of bytes simultaneously allocated via
477
<a class="link" href="libvips-memory.html#vips-tracked-malloc" title="vips_tracked_malloc ()"><code class="function">vips_tracked_malloc()</code></a>. Handy for estimating max memory requirements for a
479
<div class="refsect3">
480
<a name="id-1.2.10.8.13.5"></a><h4>Returns</h4>
481
<p> the largest number of currently allocated bytes</p>
486
<div class="refsect2">
487
<a name="vips-tracked-get-allocs"></a><h3>vips_tracked_get_allocs ()</h3>
488
<pre class="programlisting"><span class="returnvalue">int</span>
489
vips_tracked_get_allocs (<em class="parameter"><code><span class="type">void</span></code></em>);</pre>
490
<p>Returns the number of active allocations.</p>
491
<div class="refsect3">
492
<a name="id-1.2.10.8.14.5"></a><h4>Returns</h4>
493
<p> the number of active allocations</p>
498
<div class="refsect2">
499
<a name="vips-tracked-open"></a><h3>vips_tracked_open ()</h3>
500
<pre class="programlisting"><span class="returnvalue">int</span>
501
vips_tracked_open (<em class="parameter"><code>const <span class="type">char</span> *pathname</code></em>,
502
<em class="parameter"><code><span class="type">int</span> flags</code></em>,
503
<em class="parameter"><code>...</code></em>);</pre>
504
<p>Exactly as open(2), but the number of files current open via
505
<a class="link" href="libvips-memory.html#vips-tracked-open" title="vips_tracked_open ()"><code class="function">vips_tracked_open()</code></a> is available via <a class="link" href="libvips-memory.html#vips-tracked-get-files" title="vips_tracked_get_files ()"><code class="function">vips_tracked_get_files()</code></a>. This is used
506
by the vips operation cache to drop cache when the number of files
507
available is low.</p>
508
<p>You must only close the file descriptor with <a class="link" href="libvips-memory.html#vips-tracked-close" title="vips_tracked_close ()"><code class="function">vips_tracked_close()</code></a>.</p>
509
<p>See also: <a class="link" href="libvips-memory.html#vips-tracked-close" title="vips_tracked_close ()"><code class="function">vips_tracked_close()</code></a>, <a class="link" href="libvips-memory.html#vips-tracked-get-files" title="vips_tracked_get_files ()"><code class="function">vips_tracked_get_files()</code></a>.</p>
510
<div class="refsect3">
511
<a name="id-1.2.10.8.15.7"></a><h4>Parameters</h4>
512
<div class="informaltable"><table width="100%" border="0">
514
<col width="150px" class="parameters_name">
515
<col class="parameters_description">
516
<col width="200px" class="parameters_annotations">
520
<td class="parameter_name"><p>pathname</p></td>
521
<td class="parameter_description"><p>name of file to open</p></td>
522
<td class="parameter_annotations"> </td>
525
<td class="parameter_name"><p>flags</p></td>
526
<td class="parameter_description"><p>flags for <code class="function">open()</code></p></td>
527
<td class="parameter_annotations"> </td>
532
<div class="refsect3">
533
<a name="id-1.2.10.8.15.8"></a><h4>Returns</h4>
534
<p> a file descriptor, or -1 on error.</p>
539
<div class="refsect2">
540
<a name="vips-tracked-close"></a><h3>vips_tracked_close ()</h3>
541
<pre class="programlisting"><span class="returnvalue">int</span>
542
vips_tracked_close (<em class="parameter"><code><span class="type">int</span> fd</code></em>);</pre>
543
<p>Exactly as close(2), but update the number of files currently open via
544
<a class="link" href="libvips-memory.html#vips-tracked-get-files" title="vips_tracked_get_files ()"><code class="function">vips_tracked_get_files()</code></a>. This is used
545
by the vips operation cache to drop cache when the number of files
546
available is low.</p>
547
<p>You must only close file descriptors opened with <a class="link" href="libvips-memory.html#vips-tracked-open" title="vips_tracked_open ()"><code class="function">vips_tracked_open()</code></a>.</p>
548
<p>See also: <a class="link" href="libvips-memory.html#vips-tracked-open" title="vips_tracked_open ()"><code class="function">vips_tracked_open()</code></a>, <a class="link" href="libvips-memory.html#vips-tracked-get-files" title="vips_tracked_get_files ()"><code class="function">vips_tracked_get_files()</code></a>.</p>
549
<div class="refsect3">
550
<a name="id-1.2.10.8.16.7"></a><h4>Parameters</h4>
551
<div class="informaltable"><table width="100%" border="0">
553
<col width="150px" class="parameters_name">
554
<col class="parameters_description">
555
<col width="200px" class="parameters_annotations">
558
<td class="parameter_name"><p>fd</p></td>
559
<td class="parameter_description"><p>file to <code class="function">close()</code></p></td>
560
<td class="parameter_annotations"> </td>
564
<div class="refsect3">
565
<a name="id-1.2.10.8.16.8"></a><h4>Returns</h4>
566
<p> a file descriptor, or -1 on error.</p>
571
<div class="refsect2">
572
<a name="vips-tracked-get-files"></a><h3>vips_tracked_get_files ()</h3>
573
<pre class="programlisting"><span class="returnvalue">int</span>
574
vips_tracked_get_files (<em class="parameter"><code><span class="type">void</span></code></em>);</pre>
575
<p>Returns the number of open files.</p>
576
<div class="refsect3">
577
<a name="id-1.2.10.8.17.5"></a><h4>Returns</h4>
578
<p> the number of open files</p>
583
<div class="refsect1">
584
<a name="libvips-memory.other_details"></a><h2>Types and Values</h2>
481
587
<div class="footer">
483
Generated by GTK-Doc V1.19</div>
589
Generated by GTK-Doc V1.20</div>
b'\\ No newline at end of file'