Howto resize arrays without loosing data


onurozturk
10-24-2010, 04:35 AM
Hi,

In the book it mentions about a method called resize which is supposed to resize an array without preserving its contents. In my application I have to dynamically resize an array in order to accomodate newcoming array members determined in runtime. Could you suggest a way to do this? Can using stl vector methods like push back in conjunction with NR types be a remedy? If so, an example piece of code for me to see the syntax would be greatly appreciated.

Thanks,
Onur

davekw7x
10-24-2010, 09:12 AM
...Can using stl vector methods like push back in conjunction with NR types be a remedy?NR vector types do not have a push_back() method defined.

You can create a new VecDoub (or whatever) with the size you want it to be then copy, element by element, the old vector values to the new vector and delete the old vector.


If that doesn't help enough, then give us some code where you need to do this and give us a little more information. (Is it inside a function? How was the NR vector passed to the function? Pointer? What? How was the old vector created? Stuff like that.)


Regards,

Dave

onurozturk
10-30-2010, 02:32 AM
Thanks Dave, I could follow the way you you suggested, since I know in my application the maximum size of the array to be copied.