Path: utzoo!utgpu!attcan!uunet!husc6!bloom-beacon!gatech!rutgers!mailrus!ames!killer!pollux!dalsqnt!usl!pcb From: pcb@usl.usl.edu (Peter C. Bahrs) Newsgroups: comp.lang.c Subject: Re: Is malloc() or calloc() "better"? Summary: What about a null string check? Message-ID: <620@usl.usl.edu> Date: 5 Jan 89 20:39:30 GMT References: <9254@smoke.BRL.MIL> Organization: CACS, Lafayette, LA, USA Lines: 17 In article <9254@smoke.BRL.MIL>, gwyn@smoke.BRL.MIL (Doug Gwyn ) writes: > In article slores%gables.span@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.