Path: utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!rutgers!cmcl2!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn ) Newsgroups: comp.lang.c Subject: Re: Is malloc() or calloc() "better"? Message-ID: <9254@smoke.BRL.MIL> Date: 2 Jan 89 02:49:00 GMT References: Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 18 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() >instead of calloc(). It seems to me that, with the headache I always get >thinking of C strings, calloc would be a more common procedure. Would someone >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 advantage. calloc() is only useful when you definitely want 0-valued chars (NOT other data types) for the initial contents of a newly allocated object. (In non-portable applications, one can sometimes use calloc() to obtain 0 values for other structure member types, depending on the internal representation used by the architecture, but why get in the habit of using non-portable kludges when the task is easily enough done portably?)