[comp.lang.c] How to free calloc

HEPING@kuhub.cc.ukans.edu (08/20/89)

Question:
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)"?

Thanks for help.

Phil

gwyn@smoke.BRL.MIL (Doug Gwyn) (08/28/89)

In article <9208@kuhub.cc.ukans.edu> HEPING@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.)