[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
8.3.1 Vector allocation
The functions for allocating memory to a vector follow the style of
malloc
and free
. In addition they also perform their own
error checking. If there is insufficient memory available to allocate a
vector then the functions call the GSL error handler (with an error
number of GSL_ENOMEM
) in addition to returning a null
pointer. Thus if you use the library error handler to abort your program
then it isn't necessary to check every alloc
.
- Function: gsl_vector * gsl_vector_alloc (size_t n)
This function creates a vector of length n, returning a pointer to a newly initialized vector struct. A new block is allocated for the elements of the vector, and stored in the block component of the vector struct. The block is “owned” by the vector, and will be deallocated when the vector is deallocated.
- Function: gsl_vector * gsl_vector_calloc (size_t n)
This function allocates memory for a vector of length n and initializes all the elements of the vector to zero.
- Function: void gsl_vector_free (gsl_vector * v)
This function frees a previously allocated vector v. If the vector was created using
gsl_vector_alloc
then the block underlying the vector will also be deallocated. If the vector has been created from another object then the memory is still owned by that object and will not be deallocated. The vector v must be a valid vector object (a null pointer is not allowed).