Newsgroups: comp.parallel.pvm
From: wrankin@ee.duke.edu (William T. Rankin)
Subject: Re: realloc() in pvm
Organization: Duke University EE Dept.; Durham, NC
Date: 18 Jan 1995 14:53:24 GMT
Message-ID: <3fja14$1dl@news.duke.edu>

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.

What's the platform?  The OS?

I've been using realloc() in conjunction w/ PVM on several
different platforms (Solaris 2.3, Linux) and haven't seen any problems.

|> Debugger does not help much.
|> Is there any caution I need to take when I use realloc?

only the fact that the realloc is basically a malloc/memcopy/free 
sequence, so that any pointers into the old data block will nolonger
be valid after the realloc() (important if you are reallocing linked
list buffers) or using external pointers into your array.  you don't 
seem to have these problems.



|> The basic structure is following
|> 
|> main()
|> {
|>      float *data;
|>      
|>      .......
|> 
|>      pvm_recv(...);
|>      pvm_upkint(&size,....);
|>      data = (float *) sizeof(float)*size;
                         ^^^^^^^^^^^^^^^^^^
ummm, do you have a malloc here?

|>      ........
|> 
|>      for ( .....  ) {
|> 
|>         .....
|> 
|>          pvm_initsend(.....);
|>          pvm_pkint(&size, .......);
|>          pvm_pkfloat(data, size, ....);
|> 
|>          pvm_recv(....)
|>          pvm_upkint(&size2, ....);
|>          if ( size < size2 ) {
|>               data = (float *) realloc(data, sizeof(float)*size2);
|>               size = size2;
|>          }
|>          pvm_upkfloat(data, size, ...);
|>       
|>          .......
|>      }
|>      .......
|> }

one thing I would put in here is to check to malloc() and realloc() 
to see if they return NULL pointers, indicating insufficient memory,
or other problems.

Good luck,

-bill

-- 
----                                /       __/    /    /
bill rankin                        /              /    /
wrankin@ee.duke.edu               ___  /    /    /    /
philosopher/coffee-drinker       /    /    /    /    /
molecules-R-us                  /    /    /    /    /
                             _______/  __/  __/  __/

We staunch traditionalists know that appearence is everything.
Technique is nowhere near as important as having your pleats straight
when you die
                                 - Steve Gombosi


