Blame doc/mainpage.dox

rpm-build 95f51c
/**
rpm-build 95f51c
 * @mainpage
rpm-build 95f51c
 *
rpm-build 95f51c
 * talloc is a hierarchical, reference counted memory pool system with
rpm-build 95f51c
 * destructors. It is the core memory allocator used in Samba.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @section talloc_download Download
rpm-build 95f51c
 *
rpm-build 95f51c
 * You can download the latest releases of talloc from the
rpm-build 95f51c
 * talloc directory
rpm-build 95f51c
 * on the samba public source archive.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @section main-tutorial Tutorial
rpm-build 95f51c
 *
rpm-build 95f51c
 * You should start by reading @subpage libtalloc_tutorial, then reading the documentation of
rpm-build 95f51c
 * the interesting functions as you go.
rpm-build 95f51c
rpm-build 95f51c
 * @section talloc_bugs Discussion and bug reports
rpm-build 95f51c
 *
rpm-build 95f51c
 * talloc does not currently have its own mailing list or bug tracking system.
rpm-build 95f51c
 * For now, please use the
rpm-build 95f51c
 * samba-technical
rpm-build 95f51c
 * mailing list, and the
rpm-build 95f51c
 * Samba bugzilla
rpm-build 95f51c
 * bug tracking system.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @section talloc_devel Development
rpm-build 95f51c
 * You can download the latest code either via git or rsync.
rpm-build 95f51c
 *
rpm-build 95f51c
 * To fetch via git see the following guide:
rpm-build 95f51c
 *
rpm-build 95f51c
 * Using Git for Samba Development
rpm-build 95f51c
 *
rpm-build 95f51c
 * Once you have cloned the tree switch to the master branch and cd into the
rpm-build 95f51c
 * lib/tevent directory.
rpm-build 95f51c
 *
rpm-build 95f51c
 * To fetch via rsync use this command:
rpm-build 95f51c
 *
rpm-build 95f51c
 * rsync -Pavz samba.org::ftp/unpacked/standalone_projects/lib/talloc .
rpm-build 95f51c
 *
rpm-build 95f51c
 * @section talloc_preample Preamble
rpm-build 95f51c
 *
rpm-build 95f51c
 * talloc is a hierarchical, reference counted memory pool system with
rpm-build 95f51c
 * destructors.
rpm-build 95f51c
 *
rpm-build 95f51c
 * Perhaps the biggest difference from other memory pool systems is that there
rpm-build 95f51c
 * is no distinction between a "talloc context" and a "talloc pointer". Any
rpm-build 95f51c
 * pointer returned from talloc() is itself a valid talloc context. This means
rpm-build 95f51c
 * you can do this:
rpm-build 95f51c
 *
rpm-build 95f51c
 * @code
rpm-build 95f51c
 *      struct foo *X = talloc(mem_ctx, struct foo);
rpm-build 95f51c
 *      X->name = talloc_strdup(X, "foo");
rpm-build 95f51c
 * @endcode
rpm-build 95f51c
 *
rpm-build 95f51c
 * The pointer X->name would be a "child" of the talloc context "X" which is
rpm-build 95f51c
 * itself a child of mem_ctx. So if you do talloc_free(mem_ctx) then it is all
rpm-build 95f51c
 * destroyed, whereas if you do talloc_free(X) then just X and X->name are
rpm-build 95f51c
 * destroyed, and if you do talloc_free(X->name) then just the name element of
rpm-build 95f51c
 * X is destroyed.
rpm-build 95f51c
 *
rpm-build 95f51c
 * If you think about this, then what this effectively gives you is an n-ary
rpm-build 95f51c
 * tree, where you can free any part of the tree with talloc_free().
rpm-build 95f51c
 *
rpm-build 95f51c
 * If you find this confusing, then run the testsuite to watch talloc in
rpm-build 95f51c
 * action. You may also like to add your own tests to testsuite.c to clarify
rpm-build 95f51c
 * how some particular situation is handled.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @section talloc_performance Performance
rpm-build 95f51c
 *
rpm-build 95f51c
 * All the additional features of talloc() over malloc() do come at a price. We
rpm-build 95f51c
 * have a simple performance test in Samba4 that measures talloc() versus
rpm-build 95f51c
 * malloc() performance, and it seems that talloc() is about 4% slower than
rpm-build 95f51c
 * malloc() on my x86 Debian Linux box. For Samba, the great reduction in code
rpm-build 95f51c
 * complexity that we get by using talloc makes this worthwhile, especially as
rpm-build 95f51c
 * the total overhead of talloc/malloc in Samba is already quite small.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @section talloc_named Named blocks
rpm-build 95f51c
 *
rpm-build 95f51c
 * Every talloc chunk has a name that can be used as a dynamic type-checking
rpm-build 95f51c
 * system. If for some reason like a callback function you had to cast a
rpm-build 95f51c
 * "struct foo *" to a "void *" variable, later you can safely reassign the
rpm-build 95f51c
 * "void *" pointer to a "struct foo *" by using the talloc_get_type() or
rpm-build 95f51c
 * talloc_get_type_abort() macros.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @code
rpm-build 95f51c
 *      struct foo *X = talloc_get_type_abort(ptr, struct foo);
rpm-build 95f51c
 * @endcode
rpm-build 95f51c
 *
rpm-build 95f51c
 * This will abort if "ptr" does not contain a pointer that has been created
rpm-build 95f51c
 * with talloc(mem_ctx, struct foo).
rpm-build 95f51c
 *
rpm-build 95f51c
 * @section talloc_threading Multi-threading
rpm-build 95f51c
 *
rpm-build 95f51c
 * talloc itself does not deal with threads. It is thread-safe (assuming the
rpm-build 95f51c
 * underlying "malloc" is), as long as each thread uses different memory
rpm-build 95f51c
 * contexts.
rpm-build 95f51c
 *
rpm-build 95f51c
 * If two threads uses the same context then they need to synchronize in order
rpm-build 95f51c
 * to be safe. In particular:
rpm-build 95f51c
 *
rpm-build 95f51c
 *   - when using talloc_enable_leak_report(), giving directly NULL as a parent
rpm-build 95f51c
 *     context implicitly refers to a hidden "null context" global variable, so
rpm-build 95f51c
 *     this should not be used in a multi-threaded environment without proper
rpm-build 95f51c
 *     synchronization. In threaded code turn off null tracking using
rpm-build 95f51c
 *     talloc_disable_null_tracking().
rpm-build 95f51c
 *   - the context returned by talloc_autofree_context() is also global so
rpm-build 95f51c
 *     shouldn't be used by several threads simultaneously without
rpm-build 95f51c
 *     synchronization.
rpm-build 95f51c
 *
rpm-build 95f51c
 */