Mail Archives: djgpp/2000/02/29/08:52:17
On Mon, 28 Feb 2000, Marcus wrote:
> If I have a function like this
> func (char* str)
>
> Is it impossible to know if the function have been called this way
> func ("...");
> or
> char* a = malloc(10);
> func (a);
> ?
The usual paradigm in C programs is to place the responsibility of
freeing memory on the same code which allocated that memory. So the
code which allocates memory should keep track of what it allocates and
free it as needed.
If you are talking about some implementation of a function which frees
memory, the usual way to do this is to have some data structure which
records allocated blocks, and check the pointer against that data
structure. This requires cooperation between the function which
allocates memory and the one which frees it.
- Raw text -