Mail Archives: djgpp/2000/02/07/12:33:57
> ----------
> From: Martin Chan[SMTP:s987517 AT mailserv DOT cuhk DOT edu DOT hk]
> Reply To: djgpp AT delorie DOT com
> Sent: 07 February 2000 13:16
> To: djgpp AT delorie DOT com
> Subject: Memory allocation
>
> Hi.
> I define a structure as below:
>
> typedef struct
> {
> int col, row;
> double **array;
> } *Matrix;
>
> Matrix transposed_matrix ;
> int col, i, row;
>
> and then create a 2-D dynamic array as below:
>
> transposed_matrix->array=(double**)calloc(row, sizeof(double*);
> --(transposed_matrix->array); /*offset pointer*/
>
> for(i=1; i<=col; i++)
> {
> transposed_matrix->array[i]=(double*)calloc(col, sizeof(double));
> --(transposed_matrix->array[i]); /*offset pointer*/
> }
>
> Then, when I try to free the dynamic array as below:
>
> for(i=1; i<=col; i++)
> free(transposed_matrix->array[i]+1)
------------------------------
> free(transposed_matrix->array+1);
>
try free(transposed_matrix->array); instead. Also; have you
allocated transposed_matrix ?
-----------------------
> General Protection Exception error happens.
> I am puzzled. Thanks for any help.
>
>
>
- Raw text -