Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!texbell!nuchat!sugar!ficc!peter From: peter@ficc.ferranti.com (Peter da Silva) Newsgroups: comp.lang.c Subject: Re: free (NULL) Message-ID: Date: 1 Jun 90 17:29:47 GMT References: <1771@mindlink.UUCP> <2574@skye.ed.ac.uk> <1074:May3000:24:1990@stealth.acf.nyu.edu> <3102@goanna.cs.rmit.oz.au> <3466:May3022:56:1890@stealth.acf.nyu.edu> <9YT3MP@xds13.ferranti.com> <270:Jun113:33:1590@stealth.acf.nyu.edu> Reply-To: peter@ficc.ferranti.com (Peter da Silva) Organization: Xenix Support, FICC Lines: 34 In article <270:Jun113:33:1590@stealth.acf.nyu.edu> brnstnd@stealth.acf.nyu.edu (Dan Bernstein) writes: > In article <9YT3MP@xds13.ferranti.com> peter@ficc.ferranti.com (Peter da Silva) writes: > > In article <3466:May3022:56:1890@stealth.acf.nyu.edu> brnstnd@stealth.acf.nyu.edu (Dan Bernstein) writes: > > > Namely: Whatever you allocate inside a routine, you also deallocate > > > inside that routine. If your memory needs are variable, provide enough > > > information to your callers that they can allocate for you. (This is > > > called ``passing the buck.'') > > I disagree with this entirely. > So what are you disagreeing with? The paragraph quoted above. Consider a routine "readline(fp)". this (hypothetical) routine reads in a line of text and allocates and returns a pointer to it. It appears that you do not believe that this is a reasonable thing to do. Please correct me if I am misinterpreting your message. Consider the commonly implemented routine "strdup" that allocates a copy of a string and returns a pointer to the copy. The model of pulling fully-formed "things" out of a pool, manipulating them, and eventually dropping them back in is perfectly valid and often useful. > I don't think I'm totally off base, > because Boyd Roberts made the same three-way classification in a > simultaneous article. He didn't make any hard-and-fast rule about never returning a malloc-ed chunk of memory to ones parent. Just make sure that the interface is properly documented and consistent. -- `-_-' Peter da Silva. +1 713 274 5180. 'U` Have you hugged your wolf today? @FIN Dirty words: Zhghnyyl erphefvir vayvar shapgvbaf.