4 * talloc is a hierarchical, reference counted memory pool system with
5 * destructors. It is the core memory allocator used in Samba.
7 * @section talloc_download Download
9 * You can download the latest releases of talloc from the
10 * <a href="http://samba.org/ftp/talloc" target="_blank">talloc directory</a>
11 * on the samba public source archive.
13 * @section main-tutorial Tutorial
15 * You should start by reading @subpage libtalloc_tutorial, then reading the documentation of
16 * the interesting functions as you go.
18 * @section talloc_bugs Discussion and bug reports
20 * talloc does not currently have its own mailing list or bug tracking system.
21 * For now, please use the
22 * <a href="https://lists.samba.org/mailman/listinfo/samba-technical" target="_blank">samba-technical</a>
23 * mailing list, and the
24 * <a href="http://bugzilla.samba.org/" target="_blank">Samba bugzilla</a>
25 * bug tracking system.
27 * @section talloc_devel Development
28 * You can download the latest code either via git or rsync.
30 * To fetch via git see the following guide:
32 * <a href="http://wiki.samba.org/index.php/Using_Git_for_Samba_Development" target="_blank">Using Git for Samba Development</a>
34 * Once you have cloned the tree switch to the master branch and cd into the
35 * lib/tevent directory.
37 * To fetch via rsync use this command:
39 * rsync -Pavz samba.org::ftp/unpacked/standalone_projects/lib/talloc .
41 * @section talloc_preample Preamble
43 * talloc is a hierarchical, reference counted memory pool system with
46 * Perhaps the biggest difference from other memory pool systems is that there
47 * is no distinction between a "talloc context" and a "talloc pointer". Any
48 * pointer returned from talloc() is itself a valid talloc context. This means
52 * struct foo *X = talloc(mem_ctx, struct foo);
53 * X->name = talloc_strdup(X, "foo");
56 * The pointer X->name would be a "child" of the talloc context "X" which is
57 * itself a child of mem_ctx. So if you do talloc_free(mem_ctx) then it is all
58 * destroyed, whereas if you do talloc_free(X) then just X and X->name are
59 * destroyed, and if you do talloc_free(X->name) then just the name element of
62 * If you think about this, then what this effectively gives you is an n-ary
63 * tree, where you can free any part of the tree with talloc_free().
65 * If you find this confusing, then run the testsuite to watch talloc in
66 * action. You may also like to add your own tests to testsuite.c to clarify
67 * how some particular situation is handled.
69 * @section talloc_performance Performance
71 * All the additional features of talloc() over malloc() do come at a price. We
72 * have a simple performance test in Samba4 that measures talloc() versus
73 * malloc() performance, and it seems that talloc() is about 4% slower than
74 * malloc() on my x86 Debian Linux box. For Samba, the great reduction in code
75 * complexity that we get by using talloc makes this worthwhile, especially as
76 * the total overhead of talloc/malloc in Samba is already quite small.
78 * @section talloc_named Named blocks
80 * Every talloc chunk has a name that can be used as a dynamic type-checking
81 * system. If for some reason like a callback function you had to cast a
82 * "struct foo *" to a "void *" variable, later you can safely reassign the
83 * "void *" pointer to a "struct foo *" by using the talloc_get_type() or
84 * talloc_get_type_abort() macros.
87 * struct foo *X = talloc_get_type_abort(ptr, struct foo);
90 * This will abort if "ptr" does not contain a pointer that has been created
91 * with talloc(mem_ctx, struct foo).
93 * @section talloc_threading Multi-threading
95 * talloc itself does not deal with threads. It is thread-safe (assuming the
96 * underlying "malloc" is), as long as each thread uses different memory
99 * If two threads uses the same context then they need to synchronize in order
100 * to be safe. In particular:
102 * - when using talloc_enable_leak_report(), giving directly NULL as a parent
103 * context implicitly refers to a hidden "null context" global variable, so
104 * this should not be used in a multi-threaded environment without proper
106 * - the context returned by talloc_autofree_context() is also global so
107 * shouldn't be used by several threads simultaneously without