Path: utzoo!attcan!uunet!yale!wald-david From: wald-david@CS.YALE.EDU (david wald) Newsgroups: comp.lang.c Subject: Re: Is malloc() or calloc() "better"? Message-ID: <47017@yale-celray.yale.UUCP> Date: 6 Jan 89 04:15:22 GMT References: <9254@smoke.BRL.MIL> <46857@yale-celray.yale.UUCP> <9339@ihlpb.ATT.COM> Sender: root@yale.UUCP Reply-To: wald-david@CS.YALE.EDU (david wald) Organization: Yale University Computer Science Dept, New Haven CT 06520-2158 Lines: 32 In article <9339@ihlpb.ATT.COM> nevin1@ihlpb.UUCP (55528-Liber,N.J.) writes: >In article <46857@yale-celray.yale.UUCP> wald-david@CS.YALE.EDU (david wald) writes: >| >|There is one possibility of a situation where calloc could be more >|useful than malloc, however. In some virtual memory systems it is >|possible to allocate memory filled with a zero bit pattern without >|actually paging through the memory range. > >In this case, wouldn't malloc() just call the same routine as calloc()? >Since calloc() always has to do more work than malloc(), malloc() should >always get the best performance. It might be that malloc() would skip whatever step performed the "fill", where the fill operation actually consists of setting some tag indicating the default value for all bytes in the page. calloc() would still be slightly less efficient than malloc(), but much, much more efficient than zeroing the memory "by hand." Besides, if portability is an issue, you can't depend on malloc() doing that zeroing operation, even if it's the same as calloc() in whatever implementation you're using. As I said in my original posting, I don't know of any actual implementations that do this, although I'm told there are some where it's possible. Does anyone have any hard data on this? ============================================================================ David Wald wald-david@yale.UUCP waldave@yalevm.bitnet wald-david@cs.yale.edu "A monk, a clone and a ferengi decide to go bowling together..." ============================================================================