new talloc interface in Samba4

tridge at samba.org tridge at samba.org
Tue Sep 28 14:31:46 GMT 2004


Henrik,

 > What happens if multiple contexts have references to a pointer and the 
 > pointer is freed? I assume it then becomes child of one of the contexts 
 > having references to it.

yes, it becomes a child of the most recently created reference. You
can always use talloc_steal() to correct this if you want it somewhere
else.

 > Or put in another way what is the difference between references and being 
 > a child to a context? Unless I am mistaken this is primarlily an internal 
 > distinction from the internal talloc design and not really important to 
 > the callers, right?

yes, the aim was to make the details of who is the real parent as
hidden as possible, so that users could just call talloc_free() and
not worry about internals. 

Internally I ideally wanted each pointer to truly have N parents as
well as M children, but properly managing a n-ary tree with that
property was beyond the capabilities of my simple brain. I got a
headache just thinking about what talloc_steal() would do in that
situation :)

I might revisit this some time and write some true N-M n-ary tree
code, but for now I'm happy with how talloc has worked out.

 > And is there an example on in what kind of situations it may be desireable 
 > to have control over who becomes the parent when the original pointer is 
 > freed?

I think most users will just use talloc_free() and it will do
something reasonable. Metze was the one who asked for
talloc_unreference(), as he had a specific need for it, but I don't
think it will be widely used.

 > In addition would you mind talloc being borrowed by some other GPL 
 > projects? (credits given where credits due ofcourse)

of course, I'd be delighted for it to be used!

It should be quite easy to extract, as it has very few dependencies on
the rest of the Samba code. Specifically it depends only on
discard_const(), smb_panic(), vsnprintf(), plus the dlinklist.h
macros. Most systems already have vsnprintf(), and the rest are quite
trivial.

I should also say that much of the credit for the basic idea should go
to Alex Pankratov who wrote halloc (see http://swapped.cc/halloc/). I
wrote the new talloc code after reading the documentation for halloc. 

Cheers, Tridge


More information about the samba-technical mailing list