Newsgroups: comp.parallel.pvm
From: kumpf@apollo.HP.COM (Roger W. Kumpf)
Subject: Re: realloc() in pvm
Organization: Hewlett-Packard Company, Chelmsford, MA
Date: Wed, 18 Jan 1995 14:55:12 GMT
Message-ID: <D2Lw40.JyK@apollo.hp.com>

In article <3fho6e$oll@magus.cs.utah.edu>, hsong@asylum.cs.utah.edu (Hwal Song) writes:
|> When I used realloc, I am encountering some problem.
|> Debugger does not help much.
|> Is there any caution I need to take when I use realloc?
|> If you have any suggestion, please email me.
|> Thank you.
|> 
|> The basic structure is following
|> 
|> main()
|> {
|>      float *data;
|>      
|>      .......
|> 
|>      pvm_recv(...);
|>      pvm_upkint(&size,....);
|>      data = (float *) sizeof(float)*size;
 
...

|>               data = (float *) realloc(data, sizeof(float)*size2);

...

|> }

Are you aware that your initial value for the variable "data" is invalid?
You are computing a number based on the size of the array you want and then
using that number as a pointer.  Instead, you need to actually allocate the
memory.  I.e., data = (float *) malloc(sizeof(float)*size); .  Then when you
do a realloc(), you won't be accessing memory you don't own.

Hope this helps.

-Roger Kumpf


