Message-ID: From: Weir Matthew To: "'djgpp AT delorie DOT com'" Subject: RE: Memory allocation Date: Mon, 7 Feb 2000 16:12:10 -0000 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2650.21) Content-Type: text/plain Reply-To: djgpp AT delorie DOT com > ---------- > 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. > > >