Is malloc() or calloc() "better"?

Peter C. Bahrs pcb at usl.usl.edu
Fri Jan 6 06:39:30 AEST 1989


In article <9254 at smoke.BRL.MIL>, gwyn at smoke.BRL.MIL (Doug Gwyn ) writes:
> In article <gables.416 at umigw.miami.edu> slores%gables.span at umigw.miami.edu (Stanislaw L. Olejniczak) writes:
> >It seems to me that most programmers, in giving examples here, use malloc()
> >please enlighten me why is malloc so much more popular?
> 
> I don't understand the relevance to C strings..
> 
> Most often, once an object is allocated, it is filled with meaningful
> contents.  Seldom is what calloc() would have provided the appropriate
> contents for the object, so using calloc() would waste CPU time to no

What if you dynamically allocate strings and use malloc?... there may or may
not be a \0 in string[0]...I doubt it?  Therefore an initial call to
if (strcmp(string,""))  may or may not return true!

calloc, although more time consuming (not very much) insures empty or zero
filled memory.



More information about the Comp.lang.c mailing list