Maria Matějka <maria.matejka@nic.cz> writes:
Hello!
Just a quick reply from my phone. When adding these checks, I also wanted to zero out slab objects but then I realized that these objects should be initialized anyway after allocation and in most cases all of these would be rewritten twice.
The preferred way of using slab objects is therefore a full init by structure assignment after alloc like this:
struct foo *f = sl_alloc(...); *f = (struct foo) {...};
In cases of other allocations, there are allocz variants to zero the allocated memory instead of having to call memset, yet slabs are intended to be a fixed-size structure allocator which corresponds to a possibility of direct structure assignment.
I hope this is sufficient explanation. Feel free to dispute it or discuss anyway, I may be wrong somehow.
Well, that's certainly not what the Babel code is doing :) I'm not a huge fan of the struct assignment to pointers thing (there's the thing where it doesn't zero out padding, but mostly I just think it's ugly :)). However, I do see it is widely used in the Bird codebase, now that you mention it. And it's not a hugely invasive patch to fix the Babel code to use it, so if you prefer that I can send such a patch... -Toke