How to free calloc(3X)?

Doug Gwyn gwyn at smoke.BRL.MIL
Mon Aug 28 13:29:16 AEST 1989


In article <9208 at kuhub.cc.ukans.edu> HEPING at kuhub.cc.ukans.edu writes:
>For the fast main memory allocator calloc(), how can I free the block
>previously allocated by calloc? Can I use free() or cfree()? And why
>isn't there such a function when you look at "malloc(3X)"?

calloc() is NOT "fast"; it has to (in effect, at least) call malloc()
to obtain storage, then fill it full of zero bytes.  If you don't need
the zero fill, you are probably better off using malloc().

You're supposed to be able to free calloc()ed storage by calling free().
cfree() is an obsolete synonym for free().  (There may have been some
systems that implemented calloc()/free() differently, but these are the
current rules.)



More information about the Comp.lang.c mailing list