trouble with realloc 
Author Message
 trouble with realloc

Hi,

I am using realloc repetitively on an global integer array inside a
recursive function.  I am working on a SGI with MIPSpro compiler.
Most of the time it works OK, but at this one point when i use realloc
it returns a NULL pointer. There should be more than enough memory for
the new array, since the array size is going from 100 to 200.
I fixed the problem by making my own resize_array function based on
malloc.  Should I just leave it at that or figure out why realloc is
not working.  Here is a short excerpt of where the problem goes wrong.

Minimum_Path[0]++;
new_size = Minimum_Path[0]*num_atoms + 1;
Minimum_Path = realloc(Minimum_Path, new_size*sizeof(int) );
if (Minimum_Path == NULL)
        printf("Minimum_Path = NULL\n");

Thanks,
Denny



Sat, 10 Jan 2004 00:11:11 GMT  
 trouble with realloc

Quote:

> I am using realloc repetitively on an global integer array inside a
> recursive function.  I am working on a SGI with MIPSpro compiler.
> Most of the time it works OK, but at this one point when i use realloc
> it returns a NULL pointer. There should be more than enough memory for
> the new array, since the array size is going from 100 to 200.
> I fixed the problem by making my own resize_array function based on
> malloc.  Should I just leave it at that or figure out why realloc is
> not working.  Here is a short excerpt of where the problem goes wrong.

> Minimum_Path[0]++;
> new_size = Minimum_Path[0]*num_atoms + 1;
> Minimum_Path = realloc(Minimum_Path, new_size*sizeof(int) );
> if (Minimum_Path == NULL)
>         printf("Minimum_Path = NULL\n");

Denny...

How did you declare/define/initialize Minimum_Path?

If the problem isn't covered in the above, you might investigate the
amount of memory made available for dynamic allocation.

(My experience is with the SDE MIPS toolset using a "home grown" memory
management package, so I'm not knowledgable about the MIPSpro package.)


--
Morris Dovey
West Des Moines, Iowa USA
Available for embedded C contract work



Sat, 10 Jan 2004 01:14:20 GMT  
 trouble with realloc
Quote:
>Should I just leave it at that or figure out why realloc is not working

Yes. e.g. what parameter value do you provide in your call to realloc when
it returns 0? Maybe this problem indicates a problem in some other part of
your code. Anyway, I find it unlikely that the implementation of realloc is
buggy.


Mon, 12 Jan 2004 01:37:33 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. trouble with realloc'ing array of char *'s

2. malloc()/realloc() vs realloc()

3. Realloc failure when downsizing (was Re: Probably a simple realloc() question)

4. newbie trouble: CoCreateInstance Error + IWebBrowser trouble...

5. Override malloc,calloc,realloc and free?

6. malloc, realloc, free questions

7. realloc(): original block after error

8. malloc vs. realloc

9. How to test realloc (and valloc)

10. .::: realloc problem :::.

11. realloc() failure

12. realloc() won't work

 

 
Powered by phpBB® Forum Software