delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/02/07/12:33:57

Message-ID: <FAE74957524CD211A4F800805F890AEF01A2719E@ME_EXCHANGE>
From: Weir Matthew <Matthew DOT Weir AT cts-ltd DOT co DOT uk>
To: "'djgpp AT delorie DOT com'" <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)
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.
> 
> 
> 

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019