next up previous contents
Next: Filling a general size Up: General size vectors Previous: Creating and freeing general   Contents


Adjusting the size of a general size vector

Once a vector has been created, its size may be adjusted dynamically as needs arise. Gandalf stores the currently allocated maximum size of a vector in the vector structure, so it can determine when the size of the result of a computation will exceed the current size, and reallocate accordingly. This happens automatically when a vector is the result of a calculation, but sometimes it is necessary to explicitly set the size of a vector. This is done using the following routine.
      gan_vec_set_size ( &vx, 3 );
This resets the size of the vector vx to 3. If the size of a vector created by gan_vec_alloc() or gan_vec_form() is increased in size in this way beyond its originally allocated size, gan_vec_set_size() will automatically reallocate the vector to the new size. On the other hand, if gan_vec_form_data() was used to create the vector, it cannot be increased in size beyond the size of the array passed as the last argument into gan_vec_form_data().

Error detection: NULL is returned and the error handler is invoked on failure. The most likely failure mode is failing to reallocate the vector data, i.e. failure of a call to realloc().


next up previous contents
Next: Filling a general size Up: General size vectors Previous: Creating and freeing general   Contents
2006-03-17