free (NULL)

brnstnd at stealth.acf.nyu.edu brnstnd at stealth.acf.nyu.edu
Thu May 31 08:56:18 AEST 1990


In article <3102 at goanna.cs.rmit.oz.au> ok at goanna.cs.rmit.oz.au (Richard A. O'Keefe) writes:
> In article <1074:May3000:24:1990 at stealth.acf.nyu.edu>, brnstnd at stealth.acf.nyu.edu writes:
    [ some general comments on how to deal with the multiple-pointer ]
    [ freeing problem ]
> This doesn't quite address my problem.

Well, what about my last paragraph, which says what I do in practice?
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.'') If you do need to keep allocated memory
around between calls, only use that space internally; don't pass it up
to your parent.

> My real
> problem is how can I write library packages so that it is easy for
> *other* people using them to follow whatever protocol is necessary.

UNIX library routines generally either require the caller to provide a
pointer to the result, or keep the information in a static area that's
erased on each call. Both cases match the ``deallocate what you
allocate'' philosophy.

---Dan



More information about the Comp.lang.c mailing list