talloc is a hierarchical pool based memory allocator with destructors. It is the core memory allocator used in Samba4, and has made a huge difference in many aspects of Samba4 development.
The new talloc is a hierarchical, reference counted memory pool system with destructors. Quite a mouthful really, but not too bad once you get used to it.
Perhaps the biggest change from Samba3 is that there is no distinction between a "talloc context" and a "talloc pointer". Any pointer returned from talloc() is itself a valid talloc context. This means you can do this:
struct foo *X = talloc(mem_ctx, struct foo);
X->name = talloc_strdup(X, "foo");
and the pointer X->name would be a "child" of the talloc context "X" which is itself a child of mem_ctx. So if you do talloc_free(mem_ctx) then it is all destroyed, whereas if you do talloc_free(X) then just X and X->name are destroyed, and if you do talloc_free(X->name) then just the name element of X is destroyed.
If you think about this, then what this effectively gives you is an n-ary tree, where you can free any part of the tree with talloc_free().
Performance
All the additional features of talloc() over malloc() do come at a price. We have a simple performance test in Samba4 that measures talloc() versus malloc() performance, and it seems that talloc() is about 10% slower than malloc() on my x86 Debian Linux box. For Samba, the great reduction in code complexity that we get by using talloc makes this worthwhile, especially as the total overhead of talloc/malloc in Samba is already quite small.
Project information
- Licence:
- GNU LGPL v3
View full history Series and milestones
2.0 series is the current focus of development.
All code Code
- Version control system:
- Bazaar
- Programming languages:
- C
All packages Packages in Distributions
-
talloc source package in Xenial
Version 2.1.5-2 uploaded -
talloc source package in Trusty
Version 2.1.5-0ubuntu0.14.04.1 uploaded -
talloc source package in Squeeze
Version 2.0.1-1 uploaded -
talloc source package in Precise
Version 2.0.7-3 uploaded -
talloc source package in Oracular
Version 2.4.2-1build2 uploaded