Just a minor new twist on free()
Kevin D. Quitt
kdq at demott.COM
Sun Oct 7 03:03:52 AEST 1990
In article <1990Oct04.110928.16788 at virtech.uucp> cpcahil at virtech.uucp (Conor P. Cahill) writes:
>It appears you took my comments as a personal attack, which they were not
>meant to be. However, you raised some points that I will respond to...
>
>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
>
>No it is not. Actually, if array has greater than a small percentage
>of NULL pointers, the savings of the function call by the if test will
>be substantial. Rember, comparisons (especially comparisons against
>zero) are a very cheap operation. Function calls are not.
>
>>10000 comparisons. Before you retort about using memset() or bzero(),
>>please read the FAQ on NULL pointers ... and no, I wouldn't do it this
On the three systems I'm using, this is faster than the call without
the if, not slower! Testing for 0 is *much* faster than the overhead of
a function call - which function starts with a test for zero. So if I
test first, I pay the penalty for comparing against zero. If it's zero
I have a major win; if it's not, I pay a few percent in performance
penalty. Have you folks actually tried timing your examples instead
of just using gedanken experiments?
--
_
Kevin D. Quitt demott!kdq kdq at demott.com
DeMott Electronics Co. 14707 Keswick St. Van Nuys, CA 91405-1266
VOICE (818) 988-4975 FAX (818) 997-1190 MODEM (818) 997-4496 PEP last
96.37% of all statistics are made up.
More information about the Comp.lang.c
mailing list