Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!mips!apple!rutgers!columbia!cubmol!ping From: ping@cubmol.bio.columbia.edu (Shiping Zhang) Newsgroups: comp.lang.c Subject: Re: FREE Message-ID: <1990Mar2.221455.10586@cubmol.bio.columbia.edu> Date: 2 Mar 90 22:14:55 GMT References: <2714@stl.stc.co.uk> <1990Feb27.155133.20341@druid.uucp> <16055@haddock.ima.isc.com> <1990Mar1.140829.17199@druid.uucp> <1990Mar2.152601.8000@cubmol.bio.columbia.edu> Reply-To: ping@cubmol.bio.columbia.edu (Shiping Zhang) Organization: Dept. of Biology, Columbia Univ., New York, NY Lines: 32 In article meissner@osf.org (Michael Meissner) writes: >In article <1990Mar2.152601.8000@cubmol.bio.columbia.edu> >ping@cubmol.bio.columbia.edu (Shiping Zhang) writes: >If you are allocating a very large area, and then set the area to all >0's (or whatever bit pattern you want) on a virtual memory system, it >will force each of the pages to be faulted in, which can be bad. For >example, if you allocate a 10 meg chunk for the worst case senario, >and only use say 256K, clearing the memory would force would touch >9.75 meg of pages uselessly. A friend of mine sped up a linker on >exactly this problem. If I'm sure the worst case will need 10 meg and NO more and I want allocate that much space all at once at the very begin, then I will simply declare an ordinary variable of that size. If that space will be used for different types of data, I can define an union to deal with the problem. Otherwise, I will only malloc() 10 kb or 1 kb first, then later realloc() more space if necessary. Working with arrays, the boundries should always be checked, so no extra boaden is given to find out when realloc() should be called. Because malloc(), calloc() and the like belong to one set of functionally related routines, the way of using them should be consistant. They should all either do initialization (with the same results machine indepently) or all do not, but not some do, some don't. If initialization can not be gaurenteed to give consistent results machine indepently, then it is much much better to just leave the programers no choice but doing initialization themselves if necessary. Don't let programers debate in their mind and take chances. -ping