[Asterisk-Dev] calloc vs malloc ?
Luigi Rizzo
rizzo at icir.org
Sat Dec 24 11:16:13 MST 2005
any reason why the sequences
foo = malloc(sizeof(*foo));
if (!foo) { /* error handling */ }
memset(foo, 0, sizeof(*foo));
are not implemented with proper calloc calls ?
foo = calloc(1, sizeof(*foo));
if (!foo) { /* error handling */ }
Apart from making the code more robust (because a malloc
without a comment epxlaining why clearing is not necessary
would immediately trigger the developer's attention),
by using calloc() we would also give
the allocator a chance to hand us clean pages without
redoing the clearing ourselves.
cheers
luigi
More information about the asterisk-dev
mailing list