Re: malloc, calloc, and all that Jazz...

Roland John Turner (rjturner@nospam.socs.uts.edu.au)
Fri, 29 Mar 1996 16:33:16 +1100 (EST)

Joshua Graham Pitcher wrote:

> I don't really understand how calloc and malloc works. Is calloc (and malloc
> and dealloc) executed at compile time, or are they proper run time functions?

For reasons that will be obvious if you use consider what happens when you use
malloc() inside a recursively called function, it is a runtime allocation.

> If they are run time functions (which I think they are) where is the
> necessary info relating to these functions held? (for example, tables
> showing which memory has been alloced and dealloced, etc).
>
> If I malloc 32 bytes, then malloc 64 bytes, dealloc the first 32 bytes and
> then malloc another 24 bytes, will this 24 byte allocation slot in where the
> 32 byte allocation used to be? If so, how does it keep track of memory
> usage?

All that ANSI defines is the interface (i.e. function prototypes) and some
very limited behaviour. The internal data structures differ from OS to OS,
from compiler to compiler and even from compiler version to compiler version.

What are you trying to achieve?

- Raz rjturner@nospam.socs.uts.edu.au

"It often upsets a man's God fantasies to have (Misquoted? from )
someone shoot down one of his helicopters." (Ben Elton's "Stark" )