Just a minor new twist on free()

Sean Fagan seanf at sco.COM
Fri Oct 5 17:26:54 AEST 1990


In article <PDS.90Oct3103126 at lemming.webo.dg.com> pds at lemming.webo.dg.com (Paul D. Smith) writes:
>While your simple case might indeed not be much of a performance hit,
>what about something like:
>
>    #define ARRAY_LEN   10000
>    char *array[ARRAY_LEN], *ap;
>    int i;
>    for (ap = array, i = 0; i < ARRAY_LEN; ++i, ++ap)
>    { if (ap != NULL) free(ap); }
>
>Now, *this* is a significant performance hit, if you consider an extra
>10000 comparisons.  

And now an ANSI compliant library must have free() check for a NULL
parameter, which means that, instead of 10000 tests, you are now doing 20000
tests.  Yep.  Just love those performance increases, don't you?

Incidently, in reformating the included text to make news happy, I very
nicely got rid of the syntax error (a missing semicolon).  Tsk tsk tsk 8-).

-- 
-----------------+
Sean Eric Fagan  | "Never knock on Death's door:  ring the bell and 
seanf at sco.COM    |   run away!  Death really hates that!"
uunet!sco!seanf  |     -- Dr. Mike Stratford (Matt Frewer, "Doctor, Doctor")
(408) 458-1422   | Any opinions expressed are my own, not my employers'.



More information about the Comp.lang.c mailing list