2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
5 <refentrytitle>talloc</refentrytitle>
6 <manvolnum>3</manvolnum>
9 <refname>talloc</refname>
10 <refpurpose>hierarchical reference counted memory pool system with destructors</refpurpose>
13 <synopsis>#include <talloc/talloc.h></synopsis>
15 <refsect1><title>DESCRIPTION</title>
17 If you are used to talloc from Samba3 then please read this
18 carefully, as talloc has changed a lot.
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.
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:
32 struct foo *X = talloc(mem_ctx, struct foo);
33 X->name = talloc_strdup(X, "foo");
36 and the pointer <literal role="code">X->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->name</literal> are destroyed, and if
46 role="code">talloc_free(X->name)</literal> then just
47 the name element of <literal role="code">X</literal> is
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
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.
63 <refsect1><title>TALLOC API</title>
65 The following is a complete guide to the talloc API. Read it all at
68 <refsect2><title>(type *)talloc(const void *ctx, type);</title>
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>.
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.
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.
88 The <emphasis role="italic">ctx</emphasis> argument to talloc()
89 can be NULL, in which case a new top level context is created.
92 <refsect2><title>void *talloc_size(const void *ctx, size_t size);</title>
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
100 <refsect2><title>(typeof(ptr)) talloc_ptrtype(const void *ctx, ptr);</title>
102 The talloc_ptrtype() macro should be used when you have a pointer and
103 want to allocate memory to point at with this pointer. When compiling
104 with gcc >= 3 it is typesafe. Note this is a wrapper of talloc_size()
105 and talloc_get_name() will return the current location in the source file.
109 <refsect2><title>int talloc_free(void *ptr);</title>
111 The talloc_free() function frees a piece of talloc memory, and
112 all its children. You can call talloc_free() on any pointer
113 returned by talloc().
116 The return value of talloc_free() indicates success or failure,
117 with 0 returned for success and -1 for failure. The only
118 possible failure condition is if <emphasis
119 role="italic">ptr</emphasis> had a destructor attached to it and
120 the destructor returned -1. See <link
121 linkend="talloc_set_destructor"><quote>talloc_set_destructor()</quote></link>
122 for details on destructors.
125 If this pointer has an additional parent when talloc_free() is
126 called then the memory is not actually released, but instead the
127 most recently established parent is destroyed. See <link
128 linkend="talloc_reference"><quote>talloc_reference()</quote></link>
129 for details on establishing additional parents.
132 For more control on which parent is removed, see <link
133 linkend="talloc_unlink"><quote>talloc_unlink()</quote></link>.
136 talloc_free() operates recursively on its children.
139 <refsect2 id="talloc_reference"><title>void *talloc_reference(const void *ctx, const void *ptr);</title>
141 The talloc_reference() function makes <emphasis
142 role="italic">ctx</emphasis> an additional parent of <emphasis
143 role="italic">ptr</emphasis>.
146 The return value of talloc_reference() is always the original
147 pointer <emphasis role="italic">ptr</emphasis>, unless talloc ran
148 out of memory in creating the reference in which case it will
149 return NULL (each additional reference consumes around 48 bytes
150 of memory on intel x86 platforms).
153 If <emphasis role="italic">ptr</emphasis> is NULL, then the
154 function is a no-op, and simply returns NULL.
157 After creating a reference you can free it in one of the
164 you can talloc_free() any parent of the original pointer.
165 That will reduce the number of parents of this pointer by 1,
166 and will cause this pointer to be freed if it runs out of
172 you can talloc_free() the pointer itself. That will destroy
173 the most recently established parent to the pointer and leave
174 the pointer as a child of its current parent.
180 For more control on which parent to remove, see <link
181 linkend="talloc_unlink"><quote>talloc_unlink()</quote></link>.
184 <refsect2 id="talloc_unlink"><title>int talloc_unlink(const void *ctx, const void *ptr);</title>
186 The talloc_unlink() function removes a specific parent from
187 <emphasis role="italic">ptr</emphasis>. The <emphasis
188 role="italic">ctx</emphasis> passed must either be a context used
189 in talloc_reference() with this pointer, or must be a direct
193 Note that if the parent has already been removed using
194 talloc_free() then this function will fail and will return -1.
195 Likewise, if <emphasis role="italic">ptr</emphasis> is NULL, then
196 the function will make no modifications and return -1.
199 Usually you can just use talloc_free() instead of
200 talloc_unlink(), but sometimes it is useful to have the
201 additional control on which parent is removed.
204 <refsect2 id="talloc_set_destructor"><title>void talloc_set_destructor(const void *ptr, int (*destructor)(void *));</title>
206 The function talloc_set_destructor() sets the <emphasis
207 role="italic">destructor</emphasis> for the pointer <emphasis
208 role="italic">ptr</emphasis>. A <emphasis
209 role="italic">destructor</emphasis> is a function that is called
210 when the memory used by a pointer is about to be released. The
211 destructor receives <emphasis role="italic">ptr</emphasis> as an
212 argument, and should return 0 for success and -1 for failure.
215 The <emphasis role="italic">destructor</emphasis> can do anything
216 it wants to, including freeing other pieces of memory. A common
217 use for destructors is to clean up operating system resources
218 (such as open file descriptors) contained in the structure the
219 destructor is placed on.
222 You can only place one destructor on a pointer. If you need more
223 than one destructor then you can create a zero-length child of
224 the pointer and place an additional destructor on that.
227 To remove a destructor call talloc_set_destructor() with NULL for
231 If your destructor attempts to talloc_free() the pointer that it
232 is the destructor for then talloc_free() will return -1 and the
233 free will be ignored. This would be a pointless operation
234 anyway, as the destructor is only called when the memory is just
238 <refsect2><title>int talloc_increase_ref_count(const void *<emphasis role="italic">ptr</emphasis>);</title>
240 The talloc_increase_ref_count(<emphasis
241 role="italic">ptr</emphasis>) function is exactly equivalent to:
243 <programlisting>talloc_reference(NULL, ptr);</programlisting>
245 You can use either syntax, depending on which you think is
246 clearer in your code.
249 It returns 0 on success and -1 on failure.
252 <refsect2><title>size_t talloc_reference_count(const void *<emphasis role="italic">ptr</emphasis>);</title>
254 Return the number of references to the pointer.
257 <refsect2 id="talloc_set_name"><title>void talloc_set_name(const void *ptr, const char *fmt, ...);</title>
259 Each talloc pointer has a "name". The name is used principally
260 for debugging purposes, although it is also possible to set and
261 get the name on a pointer in as a way of "marking" pointers in
265 The main use for names on pointer is for "talloc reports". See
267 linkend="talloc_report"><quote>talloc_report_depth_cb()</quote></link>,
269 linkend="talloc_report"><quote>talloc_report_depth_file()</quote></link>,
271 linkend="talloc_report"><quote>talloc_report()</quote></link>
273 linkend="talloc_report"><quote>talloc_report()</quote></link>
275 linkend="talloc_report_full"><quote>talloc_report_full()</quote></link>
276 for details. Also see <link
277 linkend="talloc_enable_leak_report"><quote>talloc_enable_leak_report()</quote></link>
279 linkend="talloc_enable_leak_report_full"><quote>talloc_enable_leak_report_full()</quote></link>.
282 The talloc_set_name() function allocates memory as a child of the
283 pointer. It is logically equivalent to:
285 <programlisting>talloc_set_name_const(ptr, talloc_asprintf(ptr, fmt, ...));</programlisting>
287 Note that multiple calls to talloc_set_name() will allocate more
288 memory without releasing the name. All of the memory is released
289 when the ptr is freed using talloc_free().
292 <refsect2><title>void talloc_set_name_const(const void *<emphasis role="italic">ptr</emphasis>, const char *<emphasis role="italic">name</emphasis>);</title>
294 The function talloc_set_name_const() is just like
295 talloc_set_name(), but it takes a string constant, and is much
296 faster. It is extensively used by the "auto naming" macros, such
300 This function does not allocate any memory. It just copies the
301 supplied pointer into the internal representation of the talloc
302 ptr. This means you must not pass a <emphasis
303 role="italic">name</emphasis> pointer to memory that will
304 disappear before <emphasis role="italic">ptr</emphasis> is freed
308 <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>
310 The talloc_named() function creates a named talloc pointer. It
313 <programlisting>ptr = talloc_size(ctx, size);
314 talloc_set_name(ptr, fmt, ....);</programlisting>
316 <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>
318 This is equivalent to:
320 <programlisting>ptr = talloc_size(ctx, size);
321 talloc_set_name_const(ptr, name);</programlisting>
323 <refsect2><title>const char *talloc_get_name(const void *<emphasis role="italic">ptr</emphasis>);</title>
325 This returns the current name for the given talloc pointer,
326 <emphasis role="italic">ptr</emphasis>. See <link
327 linkend="talloc_set_name"><quote>talloc_set_name()</quote></link>
331 <refsect2><title>void *talloc_init(const char *<emphasis role="italic">fmt</emphasis>, ...);</title>
333 This function creates a zero length named talloc context as a top
334 level context. It is equivalent to:
336 <programlisting>talloc_named(NULL, 0, fmt, ...);</programlisting>
338 <refsect2><title>void *talloc_new(void *<emphasis role="italic">ctx</emphasis>);</title>
340 This is a utility macro that creates a new memory context hanging
341 off an exiting context, automatically naming it "talloc_new:
342 __location__" where __location__ is the source line it is called
343 from. It is particularly useful for creating a new temporary
347 <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>
349 The talloc_realloc() macro changes the size of a talloc pointer.
350 It has the following equivalences:
352 <programlisting>talloc_realloc(ctx, NULL, type, 1) ==> talloc(ctx, type);
353 talloc_realloc(ctx, ptr, type, 0) ==> talloc_free(ptr);</programlisting>
355 The <emphasis role="italic">ctx</emphasis> argument is only used
356 if <emphasis role="italic">ptr</emphasis> is not NULL, otherwise
360 talloc_realloc() returns the new pointer, or NULL on failure.
361 The call will fail either due to a lack of memory, or because the
362 pointer has more than one parent (see <link
363 linkend="talloc_reference"><quote>talloc_reference()</quote></link>).
366 <refsect2><title>void *talloc_realloc_size(const void *ctx, void *ptr, size_t size);</title>
368 the talloc_realloc_size() function is useful when the type is not
369 known so the type-safe talloc_realloc() cannot be used.
372 <refsect2><title>TYPE *talloc_steal(const void *<emphasis role="italic">new_ctx</emphasis>, const TYPE *<emphasis role="italic">ptr</emphasis>);</title>
374 The talloc_steal() function changes the parent context of a
375 talloc pointer. It is typically used when the context that the
376 pointer is currently a child of is going to be freed and you wish
377 to keep the memory for a longer time.
380 The talloc_steal() function returns the pointer that you pass it.
381 It does not have any failure modes.
384 NOTE: It is possible to produce loops in the parent/child
385 relationship if you are not careful with talloc_steal(). No
386 guarantees are provided as to your sanity or the safety of your
390 <refsect2><title>TYPE *talloc_move(const void *<emphasis role="italic">new_ctx</emphasis>, TYPE **<emphasis role="italic">ptr</emphasis>);</title>
392 The talloc_move() function is a wrapper around
393 talloc_steal() which zeros the source pointer after the
394 move. This avoids a potential source of bugs where a
395 programmer leaves a pointer in two structures, and uses the
396 pointer from the old structure after it has been moved to a
400 <refsect2><title>size_t talloc_total_size(const void *<emphasis role="italic">ptr</emphasis>);</title>
402 The talloc_total_size() function returns the total size in bytes
403 used by this pointer and all child pointers. Mostly useful for
407 Passing NULL is allowed, but it will only give a meaningful
408 result if talloc_enable_leak_report() or
409 talloc_enable_leak_report_full() has been called.
412 <refsect2><title>size_t talloc_total_blocks(const void *<emphasis role="italic">ptr</emphasis>);</title>
414 The talloc_total_blocks() function returns the total memory block
415 count used by this pointer and all child pointers. Mostly useful
419 Passing NULL is allowed, but it will only give a meaningful
420 result if talloc_enable_leak_report() or
421 talloc_enable_leak_report_full() has been called.
424 <refsect2 id="talloc_report"><title>void talloc_report(const void *ptr, FILE *f);</title>
426 The talloc_report() function prints a summary report of all
427 memory used by <emphasis role="italic">ptr</emphasis>. One line
428 of report is printed for each immediate child of ptr, showing the
429 total memory and number of blocks used by that child.
432 You can pass NULL for the pointer, in which case a report is
433 printed for the top level memory context, but only if
434 talloc_enable_leak_report() or talloc_enable_leak_report_full()
438 <refsect2 id="talloc_report_full"><title>void talloc_report_full(const void *<emphasis role="italic">ptr</emphasis>, FILE *<emphasis role="italic">f</emphasis>);</title>
440 This provides a more detailed report than talloc_report(). It
441 will recursively print the entire tree of memory referenced by
442 the pointer. References in the tree are shown by giving the name
443 of the pointer that is referenced.
446 You can pass NULL for the pointer, in which case a report is
447 printed for the top level memory context, but only if
448 talloc_enable_leak_report() or talloc_enable_leak_report_full()
452 <refsect2 id="talloc_report_depth_cb">
453 <funcsynopsis><funcprototype>
454 <funcdef>void <function>talloc_report_depth_cb</function></funcdef>
455 <paramdef><parameter>const void *ptr</parameter></paramdef>
456 <paramdef><parameter>int depth</parameter></paramdef>
457 <paramdef><parameter>int max_depth</parameter></paramdef>
458 <paramdef><parameter>void (*callback)(const void *ptr, int depth, int max_depth, int is_ref, void *priv)</parameter></paramdef>
459 <paramdef><parameter>void *priv</parameter></paramdef>
460 </funcprototype></funcsynopsis>
462 This provides a more flexible reports than talloc_report(). It
463 will recursively call the callback for the entire tree of memory
464 referenced by the pointer. References in the tree are passed with
465 <emphasis role="italic">is_ref = 1</emphasis> and the pointer that is referenced.
468 You can pass NULL for the pointer, in which case a report is
469 printed for the top level memory context, but only if
470 talloc_enable_leak_report() or talloc_enable_leak_report_full()
474 The recursion is stopped when depth >= max_depth.
475 max_depth = -1 means only stop at leaf nodes.
478 <refsect2 id="talloc_report_depth_file">
479 <funcsynopsis><funcprototype>
480 <funcdef>void <function>talloc_report_depth_file</function></funcdef>
481 <paramdef><parameter>const void *ptr</parameter></paramdef>
482 <paramdef><parameter>int depth</parameter></paramdef>
483 <paramdef><parameter>int max_depth</parameter></paramdef>
484 <paramdef><parameter>FILE *f</parameter></paramdef>
485 </funcprototype></funcsynopsis>
487 This provides a more flexible reports than talloc_report(). It
488 will let you specify the depth and max_depth.
491 <refsect2 id="talloc_enable_leak_report"><title>void talloc_enable_leak_report(void);</title>
493 This enables calling of talloc_report(NULL, stderr) when the
494 program exits. In Samba4 this is enabled by using the
495 --leak-report command line option.
498 For it to be useful, this function must be called before any
499 other talloc function as it establishes a "null context" that
500 acts as the top of the tree. If you don't call this function
501 first then passing NULL to talloc_report() or
502 talloc_report_full() won't give you the full tree printout.
505 Here is a typical talloc report:
507 <screen format="linespecific">talloc report on 'null_context' (total 267 bytes in 15 blocks)
508 libcli/auth/spnego_parse.c:55 contains 31 bytes in 2 blocks
509 libcli/auth/spnego_parse.c:55 contains 31 bytes in 2 blocks
510 iconv(UTF8,CP850) contains 42 bytes in 2 blocks
511 libcli/auth/spnego_parse.c:55 contains 31 bytes in 2 blocks
512 iconv(CP850,UTF8) contains 42 bytes in 2 blocks
513 iconv(UTF8,UTF-16LE) contains 45 bytes in 2 blocks
514 iconv(UTF-16LE,UTF8) contains 45 bytes in 2 blocks
517 <refsect2 id="talloc_enable_leak_report_full"><title>void talloc_enable_leak_report_full(void);</title>
519 This enables calling of talloc_report_full(NULL, stderr) when the
520 program exits. In Samba4 this is enabled by using the
521 --leak-report-full command line option.
524 For it to be useful, this function must be called before any
525 other talloc function as it establishes a "null context" that
526 acts as the top of the tree. If you don't call this function
527 first then passing NULL to talloc_report() or
528 talloc_report_full() won't give you the full tree printout.
531 Here is a typical full report:
533 <screen format="linespecific">full talloc report on 'root' (total 18 bytes in 8 blocks)
534 p1 contains 18 bytes in 7 blocks (ref 0)
535 r1 contains 13 bytes in 2 blocks (ref 0)
537 p2 contains 1 bytes in 1 blocks (ref 1)
538 x3 contains 1 bytes in 1 blocks (ref 0)
539 x2 contains 1 bytes in 1 blocks (ref 0)
540 x1 contains 1 bytes in 1 blocks (ref 0)
543 <refsect2><title>(<emphasis role="italic">type</emphasis> *)talloc_zero(const void *<emphasis role="italic">ctx</emphasis>, <emphasis role="italic">type</emphasis>);</title>
545 The talloc_zero() macro is equivalent to:
547 <programlisting>ptr = talloc(ctx, type);
548 if (ptr) memset(ptr, 0, sizeof(type));</programlisting>
550 <refsect2><title>void *talloc_zero_size(const void *<emphasis role="italic">ctx</emphasis>, size_t <emphasis role="italic">size</emphasis>)</title>
552 The talloc_zero_size() function is useful when you don't have a
556 <refsect2><title>void *talloc_memdup(const void *<emphasis role="italic">ctx</emphasis>, const void *<emphasis role="italic">p</emphasis>, size_t size);</title>
558 The talloc_memdup() function is equivalent to:
560 <programlisting>ptr = talloc_size(ctx, size);
561 if (ptr) memcpy(ptr, p, size);</programlisting>
563 <refsect2><title>char *talloc_strdup(const void *<emphasis role="italic">ctx</emphasis>, const char *<emphasis role="italic">p</emphasis>);</title>
565 The talloc_strdup() function is equivalent to:
567 <programlisting>ptr = talloc_size(ctx, strlen(p)+1);
568 if (ptr) memcpy(ptr, p, strlen(p)+1);</programlisting>
570 This function sets the name of the new pointer to the passed
571 string. This is equivalent to:
573 <programlisting>talloc_set_name_const(ptr, ptr)</programlisting>
575 <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>
577 The talloc_strndup() function is the talloc equivalent of the C
578 library function strndup(3).
581 This function sets the name of the new pointer to the passed
582 string. This is equivalent to:
584 <programlisting>talloc_set_name_const(ptr, ptr)</programlisting>
586 <refsect2><title>char *talloc_append_string(const void *<emphasis role="italic">t</emphasis>, char *<emphasis role="italic">orig</emphasis>, const char *<emphasis role="italic">append</emphasis>);</title>
588 The talloc_append_string() function appends the given formatted
589 string to the given string.
592 This function sets the name of the new pointer to the new
593 string. This is equivalent to:
595 <programlisting>talloc_set_name_const(ptr, ptr)</programlisting>
597 <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>
599 The talloc_vasprintf() function is the talloc equivalent of the C
600 library function vasprintf(3).
603 This function sets the name of the new pointer to the new
604 string. This is equivalent to:
606 <programlisting>talloc_set_name_const(ptr, ptr)</programlisting>
608 <refsect2><title>char *talloc_asprintf(const void *<emphasis role="italic">t</emphasis>, const char *<emphasis role="italic">fmt</emphasis>, ...);</title>
610 The talloc_asprintf() function is the talloc equivalent of the C
611 library function asprintf(3).
614 This function sets the name of the new pointer to the passed
615 string. This is equivalent to:
617 <programlisting>talloc_set_name_const(ptr, ptr)</programlisting>
619 <refsect2><title>char *talloc_asprintf_append(char *s, const char *fmt, ...);</title>
621 The talloc_asprintf_append() function appends the given formatted
622 string to the given string.
625 This function sets the name of the new pointer to the new
626 string. This is equivalent to:
628 <programlisting>talloc_set_name_const(ptr, ptr)</programlisting>
630 <refsect2><title>(type *)talloc_array(const void *ctx, type, uint_t count);</title>
632 The talloc_array() macro is equivalent to:
634 <programlisting>(type *)talloc_size(ctx, sizeof(type) * count);</programlisting>
636 except that it provides integer overflow protection for the
637 multiply, returning NULL if the multiply overflows.
640 <refsect2><title>void *talloc_array_size(const void *ctx, size_t size, uint_t count);</title>
642 The talloc_array_size() function is useful when the type is not
643 known. It operates in the same way as talloc_array(), but takes a
644 size instead of a type.
647 <refsect2><title>(typeof(ptr)) talloc_array_ptrtype(const void *ctx, ptr, uint_t count);</title>
649 The talloc_ptrtype() macro should be used when you have a pointer to an array
650 and want to allocate memory of an array to point at with this pointer. When compiling
651 with gcc >= 3 it is typesafe. Note this is a wrapper of talloc_array_size()
652 and talloc_get_name() will return the current location in the source file.
656 <refsect2><title>void *talloc_realloc_fn(const void *ctx, void *ptr, size_t size)</title>
658 This is a non-macro version of talloc_realloc(), which is useful
659 as libraries sometimes want a realloc function pointer. A
660 realloc(3) implementation encapsulates the functionality of
661 malloc(3), free(3) and realloc(3) in one call, which is why it is
662 useful to be able to pass around a single function pointer.
665 <refsect2><title>void *talloc_autofree_context(void);</title>
667 This is a handy utility function that returns a talloc context
668 which will be automatically freed on program exit. This can be
669 used to reduce the noise in memory leak reports.
672 <refsect2><title>void *talloc_check_name(const void *ptr, const char *name);</title>
674 This function checks if a pointer has the specified <emphasis
675 role="italic">name</emphasis>. If it does then the pointer is
676 returned. It it doesn't then NULL is returned.
679 <refsect2><title>(type *)talloc_get_type(const void *ptr, type);</title>
681 This macro allows you to do type checking on talloc pointers. It
682 is particularly useful for void* private pointers. It is
685 <programlisting>(type *)talloc_check_name(ptr, #type)</programlisting>
687 <refsect2><title>talloc_set_type(const void *ptr, type);</title>
689 This macro allows you to force the name of a pointer to be a
690 particular <emphasis>type</emphasis>. This can be
691 used in conjunction with talloc_get_type() to do type checking on
695 It is equivalent to this:
697 <programlisting>talloc_set_name_const(ptr, #type)</programlisting>
700 <refsect1><title>PERFORMANCE</title>
702 All the additional features of talloc(3) over malloc(3) do come at a
703 price. We have a simple performance test in Samba4 that measures
704 talloc() versus malloc() performance, and it seems that talloc() is
705 about 10% slower than malloc() on my x86 Debian Linux box. For
706 Samba, the great reduction in code complexity that we get by using
707 talloc makes this worthwhile, especially as the total overhead of
708 talloc/malloc in Samba is already quite small.
711 <refsect1><title>SEE ALSO</title>
713 malloc(3), strndup(3), vasprintf(3), asprintf(3),
714 <ulink url="http://talloc.samba.org/"/>
717 <refsect1><title>COPYRIGHT/LICENSE</title>
719 Copyright (C) Andrew Tridgell 2004
722 This program is free software; you can redistribute it and/or modify
723 it under the terms of the GNU General Public License as published by
724 the Free Software Foundation; either version 3 of the License, or (at
725 your option) any later version.
728 This program is distributed in the hope that it will be useful, but
729 WITHOUT ANY WARRANTY; without even the implied warranty of
730 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
731 General Public License for more details.
734 You should have received a copy of the GNU General Public License
735 along with this program; if not, see http://www.gnu.org/licenses/.