Re: How to free dynamically allocated array?



Markus wrote:

> Hi,
>
> I have read the FAQ 6.16 on how to dynamically allocate a
> two-dimensional array.
>
> I do it like this:
>
> double** A = (double **)malloc(m * sizeof(double *));
> for(i = 0; i < m; i++)
> A[i] = (double *)malloc(n * sizeof(double));
>
> But how do I free it? I currently have only
>
> free(A);
>
> but I guess it is not enough.
>
> The FAQ is not clear about this.

The answer to 7.23 basically covers your question, although that's
about a dynamic structure.

http://www.eskimo.com/~scs/C-faq/q7.23.html


The advice there, one free() for every malloc() is the right one.



Brian

.



Relevant Pages