PDA

View Full Version : realloc



mickey
4th May 2008, 14:35
Hello,
does anyone explain me why the 'realloc' (at the second time) throw a runtime error?

thanks.

marcel
4th May 2008, 19:59
Your error is here:


realloc( Val_, sizeof(double) * MC.ValLength_ );


Realloc can move the memory block to a new mem location when extending, if there is not enough room at the current location. You missed the fact that the new address is returned by realloc. Therefore you should have:



Val_ = (double *)realloc( Val_, sizeof(double) * MC.ValLength_ );