Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!srhqla!demott!kdq From: kdq@demott.COM (Kevin D. Quitt) Newsgroups: comp.lang.c Subject: Re: Just a minor new twist on free() Message-ID: <687@demott.COM> Date: 6 Oct 90 17:03:52 GMT References: <1990Oct04.110928.16788@virtech.uucp> Reply-To: kdq@demott.COM (Kevin D. Quitt) Organization: DeMott Electronics Co., Van Nuys CA Lines: 44 In article <1990Oct04.110928.16788@virtech.uucp> cpcahil@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@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@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.