Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!caen!uwm.edu!ogicse!ucsd!dog.ee.lbl.gov!elf.ee.lbl.gov!torek From: torek@elf.ee.lbl.gov (Chris Torek) Newsgroups: comp.lang.c Subject: Re: Memory allocation / data access Message-ID: <11121@dog.ee.lbl.gov> Date: 19 Mar 91 19:53:23 GMT References: <29491@cs.yale.edu> <5654@male.EBay.Sun.COM> Reply-To: torek@elf.ee.lbl.gov (Chris Torek) Distribution: na Organization: Lawrence Berkeley Laboratory, Berkeley Lines: 19 X-Local-Date: Tue, 19 Mar 91 11:53:23 PST In article <5654@male.EBay.Sun.COM> harry.protoolis@uk.1.com writes: >... why do you use malloc the first time and calloc the >next ?, as they are both array allocations you should, strictly speaking, be >using calloc for both. Well, no: calloc(n,s) is *exactly* the same as malloc(n * s) plus (if the malloc succeeds) a call to memset to set all n*s `char's to '\0'. If the objects you are allocating hold something other than integral types, this `zeroing' is not useful since other types (i.e., pointers and floating types) may not have all-bits-zero `0' values. For instance, some machines use `ring 7' for all nil pointers, or a special bit for all floating point values meaning `do not trap when this floating point value is examined'. -- In-Real-Life: Chris Torek, Lawrence Berkeley Lab CSE/EE (+1 415 486 5427) Berkeley, CA Domain: torek@ee.lbl.gov