Efficient coding considered harmful?

Guy Harris guy at auspex.UUCP
Sat Oct 29 02:20:27 AEST 1988


>:     o   Use realloc instead of malloc/free pairs. Use calloc instead of
>:         malloc followed by zeroing each member.
>
>Realloc has to copy data, so this should be less efficient than just
>doing another malloc & free.

Err, umm, "realloc" is often used when you have e.g. an array with N
filled-in elements, and you want to add some more elements; in this
case, if you do another "malloc" and "free", you'll have to copy the
entire array *anyway*; some "realloc" implementations may be able to
avoid this if they can tell that the extra data can simply be pasted
onto the end of the existing array.



More information about the Comp.lang.c mailing list