S
subirs
Hi,
I am facing problem in freeing memory in the following sample code.
---------------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
int main( int argc, char **argv)
{
int i;
typedef struct
{
double *Rho;
} Packet1;
Packet1 packet;
packet.Rho=(double *)malloc(3*sizeof(double));
for(i=0;i<3;i++)
packet.Rho=0.0;
for(i=0;i<3;i++)
{
packet.Rho=i;
printf("packet.Rho[%d]=%f \n",i,packet.Rho);
}
free(packet.Rho);
if(packet.Rho != NULL)
printf("memory not freed \n");
return 0;
}
------------------------------------------------------------------------------
Output of the code says memory not freed. What should I do to free the
memory ? Another limitation is that I cannot use a pointer to the
structure as I need to use the above format of program in a parallel
code which is needed to be passed from one processor to another.
Any help will be deeply appreciated.
regards,
Subir
I am facing problem in freeing memory in the following sample code.
---------------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
int main( int argc, char **argv)
{
int i;
typedef struct
{
double *Rho;
} Packet1;
Packet1 packet;
packet.Rho=(double *)malloc(3*sizeof(double));
for(i=0;i<3;i++)
packet.Rho=0.0;
for(i=0;i<3;i++)
{
packet.Rho=i;
printf("packet.Rho[%d]=%f \n",i,packet.Rho);
}
free(packet.Rho);
if(packet.Rho != NULL)
printf("memory not freed \n");
return 0;
}
------------------------------------------------------------------------------
Output of the code says memory not freed. What should I do to free the
memory ? Another limitation is that I cannot use a pointer to the
structure as I need to use the above format of program in a parallel
code which is needed to be passed from one processor to another.
Any help will be deeply appreciated.
regards,
Subir