Just a minor new twist on free()

Joe English Muffin jeenglis at alcor.usc.edu
Thu Oct 4 15:29:07 AEST 1990


pds at lemming.webo.dg.com (Paul D. Smith) writes:

>Well, IMHO, this is just silliness.  What are you saying, that no one
>should use ANSI extensions if they have an ANSI compiler just because
>they didn't *used* to be legal?

That's a valid concern.  There are a LOT of
systems out there that don't have an ANSI
C compiler, and there will be for a long long
time to come.

...

>    #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. 

Doing the test will most likely INCREASE performance:
a test is usually cheaper than a function call, and
free() is not a trivial function.  Ever profiled a
program that made heavy use of malloc() & free()?
They eat up a lot of cycles.  (Unless the RTL is
implemented really well; personally, I've never seen a
fast implementation of malloc() & free().)


--Joe English

  jeenglis at alcor.usc.edu



More information about the Comp.lang.c mailing list