r6622: Add talloc manpage in DocBook XML, based on SGML version by Garry Williams
[samba.git] / source / lib / talloc / talloc.3.xml
1 <?xml version="1.0"?>
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
3 <refentry>
4   <refmeta>
5     <refentrytitle>talloc</refentrytitle>
6     <manvolnum>3</manvolnum>
7   </refmeta>
8   <refnamediv>
9     <refname>talloc</refname>
10 <refpurpose>hierarchical reference counted memory pool system with destructors</refpurpose>
11   </refnamediv>
12   <refsynopsisdiv>
13 <synopsis>#include &lt;talloc/talloc.h&gt;</synopsis>
14   </refsynopsisdiv>
15   <refsect1><title>DESCRIPTION</title>
16     <para>
17       If you are used to talloc from Samba3 then please read this
18       carefully, as talloc has changed a lot.
19     </para>
20     <para>
21       The new talloc is a hierarchical, reference counted memory pool
22       system with destructors.  Quite a mouthful really, but not too bad
23       once you get used to it.
24     </para>
25     <para>
26       Perhaps the biggest change from Samba3 is that there is no
27       distinction between a "talloc context" and a "talloc pointer".  Any
28       pointer returned from talloc() is itself a valid talloc context. 
29       This means you can do this:
30     </para>
31     <programlisting>
32     struct foo *X = talloc(mem_ctx, struct foo);
33     X->name = talloc_strdup(X, "foo");
34     </programlisting>
35     <para>
36       and the pointer <literal role="code">X-&gt;name</literal>
37       would be a "child" of the talloc context <literal
38       role="code">X</literal> which is itself a child of
39       <literal role="code">mem_ctx</literal>.  So if you do
40       <literal role="code">talloc_free(mem_ctx)</literal> then
41       it is all destroyed, whereas if you do <literal
42       role="code">talloc_free(X)</literal> then just <literal
43       role="code">X</literal> and <literal
44       role="code">X-&gt;name</literal> are destroyed, and if
45       you do <literal
46       role="code">talloc_free(X-&gt;name)</literal> then just
47       the name element of <literal role="code">X</literal> is
48       destroyed.
49     </para>
50     <para>
51       If you think about this, then what this effectively gives you is an
52       n-ary tree, where you can free any part of the tree with
53       talloc_free().
54     </para>
55     <para>
56       If you find this confusing, then I suggest you run the <literal
57       role="code">testsuite</literal> program to watch talloc
58       in action.  You may also like to add your own tests to <literal
59       role="code">testsuite.c</literal> to clarify how some
60       particular situation is handled.
61     </para>
62   </refsect1>
63   <refsect1><title>TALLOC API</title>
64     <para>
65       The following is a complete guide to the talloc API. Read it all at
66       least twice.
67     </para>
68     <refsect2><title>(type *)talloc(const void *ctx, type);</title>
69         <para>
70           The talloc() macro is the core of the talloc library.  It takes a
71           memory <emphasis role="italic">ctx</emphasis> and a <emphasis
72           role="italic">type</emphasis>, and returns a pointer to a new
73           area of memory of the given <emphasis
74           role="italic">type</emphasis>.
75         </para>
76         <para>
77           The returned pointer is itself a talloc context, so you can use
78           it as the <emphasis role="italic">ctx</emphasis> argument to more
79           calls to talloc() if you wish.
80         </para>
81         <para>
82           The returned pointer is a "child" of the supplied context.  This
83           means that if you talloc_free() the <emphasis
84           role="italic">ctx</emphasis> then the new child disappears as
85           well.  Alternatively you can free just the child.
86         </para>
87         <para>
88           The <emphasis role="italic">ctx</emphasis> argument to talloc()
89           can be NULL, in which case a new top level context is created.
90         </para>
91     </refsect2>
92     <refsect2><title>void *talloc_size(const void *ctx, size_t size);</title>
93         <para>
94           The function talloc_size() should be used when you don't have a
95           convenient type to pass to talloc().  Unlike talloc(), it is not
96           type safe (as it returns a void *), so you are on your own for
97           type checking.
98         </para>
99     </refsect2>
100     <refsect2><title>int talloc_free(void *ptr);</title>
101         <para>
102           The talloc_free() function frees a piece of talloc memory, and
103           all its children.  You can call talloc_free() on any pointer
104           returned by talloc().
105         </para>
106         <para>
107           The return value of talloc_free() indicates success or failure,
108           with 0 returned for success and -1 for failure.  The only
109           possible failure condition is if <emphasis
110           role="italic">ptr</emphasis> had a destructor attached to it and
111           the destructor returned -1.  See <link
112           linkend="talloc_set_destructor"><quote>talloc_set_destructor()</quote></link>
113           for details on destructors.
114         </para>
115         <para>
116           If this pointer has an additional parent when talloc_free() is
117           called then the memory is not actually released, but instead the
118           most recently established parent is destroyed.  See <link
119           linkend="talloc_reference"><quote>talloc_reference()</quote></link>
120           for details on establishing additional parents.
121         </para>
122         <para>
123           For more control on which parent is removed, see <link
124           linkend="talloc_unlink"><quote>talloc_unlink()</quote></link>.
125         </para>
126         <para>
127           talloc_free() operates recursively on its children.
128         </para>
129     </refsect2>
130     <refsect2 id="talloc_reference"><title>void *talloc_reference(const void *ctx, const void *ptr);</title>
131         <para>
132           The talloc_reference() function makes <emphasis
133           role="italic">ctx</emphasis> an additional parent of <emphasis
134           role="italic">ptr</emphasis>.
135         </para>
136         <para>
137           The return value of talloc_reference() is always the original
138           pointer <emphasis role="italic">ptr</emphasis>, unless talloc ran
139           out of memory in creating the reference in which case it will
140           return NULL (each additional reference consumes around 48 bytes
141           of memory on intel x86 platforms).
142         </para>
143         <para>
144           If <emphasis role="italic">ptr</emphasis> is NULL, then the
145           function is a no-op, and simply returns NULL.
146         </para>
147         <para>
148           After creating a reference you can free it in one of the
149           following ways:
150         </para>
151       <para>
152         <itemizedlist>
153           <listitem>
154             <para>
155               you can talloc_free() any parent of the original pointer. 
156               That will reduce the number of parents of this pointer by 1,
157               and will cause this pointer to be freed if it runs out of
158               parents.
159             </para>
160           </listitem>
161           <listitem>
162             <para>
163               you can talloc_free() the pointer itself.  That will destroy
164               the most recently established parent to the pointer and leave
165               the pointer as a child of its current parent.
166             </para>
167           </listitem>
168         </itemizedlist>
169       </para>
170       <para>
171         For more control on which parent to remove, see <link
172         linkend="talloc_unlink"><quote>talloc_unlink()</quote></link>.
173       </para>
174     </refsect2>
175     <refsect2 id="talloc_unlink"><title>int talloc_unlink(const void *ctx, const void *ptr);</title>
176         <para>
177           The talloc_unlink() function removes a specific parent from
178           <emphasis role="italic">ptr</emphasis>. The <emphasis
179           role="italic">ctx</emphasis> passed must either be a context used
180           in talloc_reference() with this pointer, or must be a direct
181           parent of ptr.
182         </para>
183         <para>
184           Note that if the parent has already been removed using
185           talloc_free() then this function will fail and will return -1. 
186           Likewise, if <emphasis role="italic">ptr</emphasis> is NULL, then
187           the function will make no modifications and return -1.
188         </para>
189         <para>
190           Usually you can just use talloc_free() instead of
191           talloc_unlink(), but sometimes it is useful to have the
192           additional control on which parent is removed.
193         </para>
194     </refsect2>
195     <refsect2 id="talloc_set_destructor"><title>void talloc_set_destructor(const void *ptr, int (*destructor)(void *));</title>
196         <para>
197           The function talloc_set_destructor() sets the <emphasis
198           role="italic">destructor</emphasis> for the pointer <emphasis
199           role="italic">ptr</emphasis>.  A <emphasis
200           role="italic">destructor</emphasis> is a function that is called
201           when the memory used by a pointer is about to be released.  The
202           destructor receives <emphasis role="italic">ptr</emphasis> as an
203           argument, and should return 0 for success and -1 for failure.
204         </para>
205         <para>
206           The <emphasis role="italic">destructor</emphasis> can do anything
207           it wants to, including freeing other pieces of memory.  A common
208           use for destructors is to clean up operating system resources
209           (such as open file descriptors) contained in the structure the
210           destructor is placed on.
211         </para>
212         <para>
213           You can only place one destructor on a pointer.  If you need more
214           than one destructor then you can create a zero-length child of
215           the pointer and place an additional destructor on that.
216         </para>
217         <para>
218           To remove a destructor call talloc_set_destructor() with NULL for
219           the destructor.
220         </para>
221         <para>
222           If your destructor attempts to talloc_free() the pointer that it
223           is the destructor for then talloc_free() will return -1 and the
224           free will be ignored.  This would be a pointless operation
225           anyway, as the destructor is only called when the memory is just
226           about to go away.
227         </para>
228     </refsect2>
229     <refsect2><title>void talloc_increase_ref_count(const void *<emphasis role="italic">ptr</emphasis>);</title>
230         <para>
231           The talloc_increase_ref_count(<emphasis
232           role="italic">ptr</emphasis>) function is exactly equivalent to:
233         </para>
234         <programlisting>talloc_reference(NULL, ptr);</programlisting>
235         <para>
236           You can use either syntax, depending on which you think is
237           clearer in your code.
238         </para>
239     </refsect2>
240     <refsect2 id="talloc_set_name"><title>void talloc_set_name(const void *ptr, const char *fmt, ...);</title>
241         <para>
242           Each talloc pointer has a "name".  The name is used principally
243           for debugging purposes, although it is also possible to set and
244           get the name on a pointer in as a way of "marking" pointers in
245           your code.
246         </para>
247         <para>
248           The main use for names on pointer is for "talloc reports".  See
249           <link
250           linkend="talloc_report"><quote>talloc_report()</quote></link>
251           and <link
252           linkend="talloc_report_full"><quote>talloc_report_full()</quote></link>
253           for details.  Also see <link
254           linkend="talloc_enable_leak_report"><quote>talloc_enable_leak_report()</quote></link>
255           and <link
256           linkend="talloc_enable_leak_report_full"><quote>talloc_enable_leak_report_full()</quote></link>.
257         </para>
258         <para>
259           The talloc_set_name() function allocates memory as a child of the
260           pointer.  It is logically equivalent to:
261         </para>
262         <programlisting>talloc_set_name_const(ptr, talloc_asprintf(ptr, fmt, ...));</programlisting>
263         <para>
264           Note that multiple calls to talloc_set_name() will allocate more
265           memory without releasing the name.  All of the memory is released
266           when the ptr is freed using talloc_free().
267         </para>
268     </refsect2>
269     <refsect2><title>void talloc_set_name_const(const void *<emphasis role="italic">ptr</emphasis>, const char *<emphasis role="italic">name</emphasis>);</title>
270         <para>
271           The function talloc_set_name_const() is just like
272           talloc_set_name(), but it takes a string constant, and is much
273           faster.  It is extensively used by the "auto naming" macros, such
274           as talloc_p().
275         </para>
276         <para>
277           This function does not allocate any memory.  It just copies the
278           supplied pointer into the internal representation of the talloc
279           ptr. This means you must not pass a <emphasis
280           role="italic">name</emphasis> pointer to memory that will
281           disappear before <emphasis role="italic">ptr</emphasis> is freed
282           with talloc_free().
283         </para>
284     </refsect2>
285     <refsect2><title>void *talloc_named(const void *<emphasis role="italic">ctx</emphasis>, size_t <emphasis role="italic">size</emphasis>, const char *<emphasis role="italic">fmt</emphasis>, ...);</title>
286         <para>
287           The talloc_named() function creates a named talloc pointer.  It
288           is equivalent to:
289         </para>
290         <programlisting>ptr = talloc_size(ctx, size);
291 talloc_set_name(ptr, fmt, ....);</programlisting>
292     </refsect2>
293     <refsect2><title>void *talloc_named_const(const void *<emphasis role="italic">ctx</emphasis>, size_t <emphasis role="italic">size</emphasis>, const char *<emphasis role="italic">name</emphasis>);</title>
294         <para>
295           This is equivalent to:
296         </para>
297         <programlisting>ptr = talloc_size(ctx, size);
298 talloc_set_name_const(ptr, name);</programlisting>
299     </refsect2>
300     <refsect2><title>const char *talloc_get_name(const void *<emphasis role="italic">ptr</emphasis>);</title>
301         <para>
302           This returns the current name for the given talloc pointer,
303           <emphasis role="italic">ptr</emphasis>. See <link
304           linkend="talloc_set_name"><quote>talloc_set_name()</quote></link>
305           for details.
306         </para>
307     </refsect2>
308     <refsect2><title>void *talloc_init(const char *<emphasis role="italic">fmt</emphasis>, ...);</title>
309         <para>
310           This function creates a zero length named talloc context as a top
311           level context.  It is equivalent to:
312         </para>
313         <programlisting>talloc_named(NULL, 0, fmt, ...);</programlisting>
314     </refsect2>
315     <refsect2><title>void *talloc_new(void *<emphasis role="italic">ctx</emphasis>);</title>
316         <para>
317           This is a utility macro that creates a new memory context hanging
318           off an exiting context, automatically naming it "talloc_new:
319           __location__" where __location__ is the source line it is called
320           from.  It is particularly useful for creating a new temporary
321           working context.
322         </para>
323     </refsect2>
324     <refsect2><title>(<emphasis role="italic">type</emphasis> *)talloc_realloc(const void *<emphasis role="italic">ctx</emphasis>, void *<emphasis role="italic">ptr</emphasis>, <emphasis role="italic">type</emphasis>, <emphasis role="italic">count</emphasis>);</title>
325         <para>
326           The talloc_realloc() macro changes the size of a talloc pointer. 
327           It has the following equivalences:
328         </para>
329         <programlisting>talloc_realloc(ctx, NULL, type, 1) ==> talloc(ctx, type);
330 talloc_realloc(ctx, ptr, type, 0)  ==> talloc_free(ptr);</programlisting>
331         <para>
332           The <emphasis role="italic">ctx</emphasis> argument is only used
333           if <emphasis role="italic">ptr</emphasis> is not NULL, otherwise
334           it is ignored.
335         </para>
336         <para>
337           talloc_realloc() returns the new pointer, or NULL on failure. 
338           The call will fail either due to a lack of memory, or because the
339           pointer has more than one parent (see <link
340           linkend="talloc_reference"><quote>talloc_reference()</quote></link>).
341         </para>
342     </refsect2>
343     <refsect2><title>void *talloc_realloc_size(const void *ctx, void *ptr, size_t size);</title>
344         <para>
345           the talloc_realloc_size() function is useful when the type is not
346           known so the type-safe talloc_realloc() cannot be used.
347         </para>
348     </refsect2>
349     <refsect2><title>void *talloc_steal(const void *<emphasis role="italic">new_ctx</emphasis>, const void *<emphasis role="italic">ptr</emphasis>);</title>
350         <para>
351           The talloc_steal() function changes the parent context of a
352           talloc pointer.  It is typically used when the context that the
353           pointer is currently a child of is going to be freed and you wish
354           to keep the memory for a longer time.
355         </para>
356         <para>
357           The talloc_steal() function returns the pointer that you pass it.
358            It does not have any failure modes.
359         </para>
360         <para>
361           NOTE: It is possible to produce loops in the parent/child
362           relationship if you are not careful with talloc_steal().  No
363           guarantees are provided as to your sanity or the safety of your
364           data if you do this.
365         </para>
366     </refsect2>
367     <refsect2><title>off_t talloc_total_size(const void *<emphasis role="italic">ptr</emphasis>);</title>
368         <para>
369           The talloc_total_size() function returns the total size in bytes
370           used by this pointer and all child pointers.  Mostly useful for
371           debugging.
372         </para>
373         <para>
374           Passing NULL is allowed, but it will only give a meaningful
375           result if talloc_enable_leak_report() or
376           talloc_enable_leak_report_full() has been called.
377         </para>
378     </refsect2>
379     <refsect2><title>off_t talloc_total_blocks(const void *<emphasis role="italic">ptr</emphasis>);</title>
380         <para>
381           The talloc_total_blocks() function returns the total memory block
382           count used by this pointer and all child pointers.  Mostly useful
383           for debugging.
384         </para>
385         <para>
386           Passing NULL is allowed, but it will only give a meaningful
387           result if talloc_enable_leak_report() or
388           talloc_enable_leak_report_full() has been called.
389         </para>
390     </refsect2>
391     <refsect2 id="talloc_report"><title>void talloc_report(const void *ptr, FILE *f);</title>
392         <para>
393           The talloc_report() function prints a summary report of all
394           memory used by <emphasis role="italic">ptr</emphasis>.  One line
395           of report is printed for each immediate child of ptr, showing the
396           total memory and number of blocks used by that child.
397         </para>
398         <para>
399           You can pass NULL for the pointer, in which case a report is
400           printed for the top level memory context, but only if
401           talloc_enable_leak_report() or talloc_enable_leak_report_full()
402           has been called.
403         </para>
404     </refsect2>
405     <refsect2 id="talloc_report_full"><title>void talloc_report_full(const void *<emphasis role="italic">ptr</emphasis>, FILE *<emphasis role="italic">f</emphasis>);</title>
406         <para>
407           This provides a more detailed report than talloc_report().  It
408           will recursively print the entire tree of memory referenced by
409           the pointer. References in the tree are shown by giving the name
410           of the pointer that is referenced.
411         </para>
412         <para>
413           You can pass NULL for the pointer, in which case a report is
414           printed for the top level memory context, but only if
415           talloc_enable_leak_report() or talloc_enable_leak_report_full()
416           has been called.
417         </para>
418     </refsect2>
419     <refsect2 id="talloc_enable_leak_report"><title>void talloc_enable_leak_report(void);</title>
420         <para>
421           This enables calling of talloc_report(NULL, stderr) when the
422           program exits.  In Samba4 this is enabled by using the
423           --leak-report command line option.
424         </para>
425         <para>
426           For it to be useful, this function must be called before any
427           other talloc function as it establishes a "null context" that
428           acts as the top of the tree.  If you don't call this function
429           first then passing NULL to talloc_report() or
430           talloc_report_full() won't give you the full tree printout.
431         </para>
432         <para>
433           Here is a typical talloc report:
434         </para>
435         <screen format="linespecific">talloc report on 'null_context' (total 267 bytes in 15 blocks)
436 libcli/auth/spnego_parse.c:55  contains   31 bytes in   2 blocks
437 libcli/auth/spnego_parse.c:55  contains   31 bytes in   2 blocks
438 iconv(UTF8,CP850)              contains   42 bytes in   2 blocks
439 libcli/auth/spnego_parse.c:55  contains   31 bytes in   2 blocks
440 iconv(CP850,UTF8)              contains   42 bytes in   2 blocks
441 iconv(UTF8,UTF-16LE)           contains   45 bytes in   2 blocks
442 iconv(UTF-16LE,UTF8)           contains   45 bytes in   2 blocks
443       </screen>
444     </refsect2>
445     <refsect2 id="talloc_enable_leak_report_full"><title>void talloc_enable_leak_report_full(void);</title>
446         <para>
447           This enables calling of talloc_report_full(NULL, stderr) when the
448           program exits.  In Samba4 this is enabled by using the
449           --leak-report-full command line option.
450         </para>
451         <para>
452           For it to be useful, this function must be called before any
453           other talloc function as it establishes a "null context" that
454           acts as the top of the tree.  If you don't call this function
455           first then passing NULL to talloc_report() or
456           talloc_report_full() won't give you the full tree printout.
457         </para>
458         <para>
459           Here is a typical full report:
460         </para>
461         <screen format="linespecific">full talloc report on 'root' (total 18 bytes in 8 blocks)
462 p1               contains     18 bytes in   7 blocks (ref 0)
463     r1               contains     13 bytes in   2 blocks (ref 0)
464         reference to: p2
465     p2               contains      1 bytes in   1 blocks (ref 1)
466     x3               contains      1 bytes in   1 blocks (ref 0)
467     x2               contains      1 bytes in   1 blocks (ref 0)
468     x1               contains      1 bytes in   1 blocks (ref 0)
469       </screen>
470     </refsect2>
471     <refsect2><title>(<emphasis role="italic">type</emphasis> *)talloc_zero(const void *<emphasis role="italic">ctx</emphasis>, <emphasis role="italic">type</emphasis>);</title>
472         <para>
473           The talloc_zero() macro is equivalent to:
474         </para>
475         <programlisting>ptr = talloc(ctx, type);
476 if (ptr) memset(ptr, 0, sizeof(type));</programlisting>
477     </refsect2>
478     <refsect2><title>void *talloc_zero_size(const void *<emphasis role="italic">ctx</emphasis>, size_t <emphasis role="italic">size</emphasis>)</title>
479         <para>
480           The talloc_zero_size() function is useful when you don't have a
481           known type.
482         </para>
483     </refsect2>
484     <refsect2><title>void *talloc_memdup(const void *<emphasis role="italic">ctx</emphasis>, const void *<emphasis role="italic">p</emphasis>, size_t size);</title>
485         <para>
486           The talloc_memdup() function is equivalent to:
487         </para>
488         <programlisting>ptr = talloc_size(ctx, size);
489 if (ptr) memcpy(ptr, p, size);</programlisting>
490     </refsect2>
491     <refsect2><title>char *talloc_strdup(const void *<emphasis role="italic">ctx</emphasis>, const char *<emphasis role="italic">p</emphasis>);</title>
492         <para>
493           The talloc_strdup() function is equivalent to:
494         </para>
495         <programlisting>ptr = talloc_size(ctx, strlen(p)+1);
496 if (ptr) memcpy(ptr, p, strlen(p)+1);</programlisting>
497         <para>
498           This function sets the name of the new pointer to the passed
499           string. This is equivalent to:
500         </para>
501         <programlisting>talloc_set_name_const(ptr, ptr)</programlisting>
502     </refsect2>
503     <refsect2><title>char *talloc_strndup(const void *<emphasis role="italic">t</emphasis>, const char *<emphasis role="italic">p</emphasis>, size_t <emphasis role="italic">n</emphasis>);</title>
504         <para>
505           The talloc_strndup() function is the talloc equivalent of the C
506           library function strndup(3).
507         </para>
508         <para>
509           This function sets the name of the new pointer to the passed
510           string. This is equivalent to:
511         </para>
512         <programlisting>talloc_set_name_const(ptr, ptr)</programlisting>
513     </refsect2>
514     <refsect2><title>char *talloc_vasprintf(const void *<emphasis role="italic">t</emphasis>, const char *<emphasis role="italic">fmt</emphasis>, va_list <emphasis role="italic">ap</emphasis>);</title>
515         <para>
516           The talloc_vasprintf() function is the talloc equivalent of the C
517           library function vasprintf(3).
518         </para>
519     </refsect2>
520     <refsect2><title>char *talloc_asprintf(const void *<emphasis role="italic">t</emphasis>, const char *<emphasis role="italic">fmt</emphasis>, ...);</title>
521         <para>
522           The talloc_asprintf() function is the talloc equivalent of the C
523           library function asprintf(3).
524         </para>
525         <para>
526           This function sets the name of the new pointer to the passed
527           string. This is equivalent to:
528         </para>
529         <programlisting>talloc_set_name_const(ptr, ptr)</programlisting>
530     </refsect2>
531     <refsect2><title>char *talloc_asprintf_append(char *s, const char *fmt, ...);</title>
532         <para>
533           The talloc_asprintf_append() function appends the given formatted
534           string to the given string.
535         </para>
536     </refsect2>
537     <refsect2><title>(type *)talloc_array(const void *ctx, type, uint_t count);</title>
538         <para>
539           The talloc_array() macro is equivalent to:
540         </para>
541         <programlisting>(type *)talloc_size(ctx, sizeof(type) * count);</programlisting>
542         <para>
543           except that it provides integer overflow protection for the
544           multiply, returning NULL if the multiply overflows.
545         </para>
546     </refsect2>
547     <refsect2><title>void *talloc_array_size(const void *ctx, size_t size, uint_t count);</title>
548         <para>
549           The talloc_array_size() function is useful when the type is not
550           known. It operates in the same way as talloc_array(), but takes a
551           size instead of a type.
552         </para>
553     </refsect2>
554     <refsect2><title>void *talloc_realloc_fn(const void *ctx, void *ptr, size_t size)</title>
555         <para>
556           This is a non-macro version of talloc_realloc(), which is useful
557           as libraries sometimes want a realloc function pointer.  A
558           realloc(3) implementation encapsulates the functionality of
559           malloc(3), free(3) and realloc(3) in one call, which is why it is
560           useful to be able to pass around a single function pointer.
561         </para>
562     </refsect2>
563     <refsect2><title>void *talloc_autofree_context(void);</title>
564         <para>
565           This is a handy utility function that returns a talloc context
566           which will be automatically freed on program exit.  This can be
567           used to reduce the noise in memory leak reports.
568         </para>
569     </refsect2>
570     <refsect2><title>void *talloc_check_name(const void *ptr, const char *name);</title>
571         <para>
572           This function checks if a pointer has the specified <emphasis
573           role="italic">name</emphasis>.  If it does then the pointer is
574           returned.  It it doesn't then NULL is returned.
575         </para>
576     </refsect2>
577     <refsect2><title>(type *)talloc_get_type(const void *ptr, type);</title>
578         <para>
579           This macro allows you to do type checking on talloc pointers.  It
580           is particularly useful for void* private pointers.  It is
581           equivalent to this:
582         </para>
583         <programlisting>(type *)talloc_check_name(ptr, #type)</programlisting>
584     </refsect2>
585     <refsect2><title>talloc_set_type(const void *ptr, type);</title>
586         <para>
587           This macro allows you to force the name of a pointer to be a
588           particular <emphasis>type</emphasis>.  This can be
589           used in conjunction with talloc_get_type() to do type checking on
590           void* pointers.
591         </para>
592         <para>
593           It is equivalent to this:
594         </para>
595         <programlisting>talloc_set_name_const(ptr, #type)</programlisting>
596     </refsect2>
597   </refsect1>
598   <refsect1><title>PERFORMANCE</title>
599     <para>
600       All the additional features of talloc(3) over malloc(3) do come at a
601       price.  We have a simple performance test in Samba4 that measures
602       talloc() versus malloc() performance, and it seems that talloc() is
603       about 10% slower than malloc() on my x86 Debian Linux box.  For
604       Samba, the great reduction in code complexity that we get by using
605       talloc makes this worthwhile, especially as the total overhead of
606       talloc/malloc in Samba is already quite small.
607     </para>
608   </refsect1>
609   <refsect1><title>SEE ALSO</title>
610     <para>
611       malloc(3), strndup(3), vasprintf(3), asprintf(3), 
612       <ulink url="http://talloc.samba.org/"/>
613     </para>
614   </refsect1>
615   <refsect1><title>COPYRIGHT/LICENSE</title>
616     <para>
617       Copyright (C) Andrew Tridgell 2004
618     </para>
619     <para>
620       This program is free software; you can redistribute it and/or modify
621       it under the terms of the GNU General Public License as published by
622       the Free Software Foundation; either version 2 of the License, or (at
623       your option) any later version.
624     </para>
625     <para>
626       This program is distributed in the hope that it will be useful, but
627       WITHOUT ANY WARRANTY; without even the implied warranty of
628       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
629       General Public License for more details.
630     </para>
631     <para>
632       You should have received a copy of the GNU General Public License
633       along with this program; if not, write to the Free Software
634       Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
635     </para>
636   </refsect1>
637 </refentry>