Path: utzoo!attcan!uunet!lll-winken!lll-ncis!helios.ee.lbl.gov!pasteur!ucbvax!bloom-beacon!adam.pika.mit.edu!scs From: scs@adam.pika.mit.edu (Steve Summit) Newsgroups: comp.lang.c Subject: Re: Is malloc() or calloc() "better"? Summary: never use calloc Message-ID: <8632@bloom-beacon.MIT.EDU> Date: 6 Jan 89 04:56:29 GMT References: Sender: daemon@bloom-beacon.MIT.EDU Reply-To: scs@adam.pika.mit.edu (Steve Summit) Lines: 27 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(). Would someone >please enlighten me why is malloc so much more popular? calloc is essentially worthless. The zero-fill operation it provides is rarely useful in portable programs, for reasons which have already correctly been mentioned. I advocate replacing any contemplated call to calloc(n, s) with malloc(n * s) followed by explicit initialization and/or zero fill, if required. I wish calloc had never been standardized; its incremental utility is quite low. (ANSI probably had no choice, though, since existing code must be protected.) There are claims that calloc can be "more efficient" (there's that word again) under contorted circumstances on virtual memory machines with demand- zero pages, but we went through all that on comp.std.c a month or two ago, and it doesn't bear repeating here. Steve Summit scs@adam.pika.mit.edu