Le Mardi 2 Septembre 2003 16:38, Silvio a Beccara a écrit :
Hi Frank,
after some time, I spotted the error. It doesn't have anything to do with arrays, but really with a negative sqrt argument in another place of the code, which I hadn't seen before.
I now have another problem: I need to extend the size of a dynamic vector, passed as VAR (i.e. by reference) to a procedure. I need to preserve the elements of the vector to be resized. I use NEW each time inside the procedure, and it works, but this fills up the stack very quickly, and I run out of memory. Do you have any suggestion?
I am not sure that I understand your problem; here is a possible solution to my interpretation of your message (dirty trick, will be hard to maintain in a few months, or by somebody else) 1 make sure that there exists only one thing pointing to your vector in the calling code. Let it be V
2 instead of passing the reference bizarre(var V: ... pass a pointer to it (it will be something much alike a pointer to a pointer) bizarre(addr(V) ... or something like that
3 inside your procedure, create your new vector, copy the relevant part of the old one into the new one, free the old one using the pointer, change V in the calling code so that it points to the new vector
The elements will be transferred from the old vector into the new one, so they are preserved, but the address of V will be changed, this is why you must be sure that it exists in only one place.
The occupation of the stack will not grow more than needed, but fragmentation may be as much a nuisance as occupation.