[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-gsl] gsl vector re-allocation
From: |
James Bergstra |
Subject: |
Re: [Help-gsl] gsl vector re-allocation |
Date: |
Tue, 18 Oct 2005 11:22:37 -0400 |
User-agent: |
Mutt/1.4.1i |
I it doesn't exist, because generally you shouldn't do it :)
There are a couple of reasons:
- a vector is not generally contiguous in memory (unlike STL vector<>!)
- a vector is not generally the owner of his memory... for instance, a
vector may be the column of a matrix.
- the data pointer has not generally been returned by free()
On the other hand, if you get a vector by gsl_vector_alloc() then you
can be assured that your vector->data pointer matches your vector->block->data
pointer. In this case, [something like] the following ugly hack should
work:
void resize(gsl_vector * vec, size_t newsize)
{
if (vec->stride != 1)
{
//probably you don't want to resize...
}
else if (vec->owner && (vec->block->data == vec->data))
{
double * p = realloc(vec->block->data, newsize * sizeof(double));
vec->block->data = vec->data = p;
vec->size = newsize;
}
}
On Tue, Oct 18, 2005 at 11:55:02AM +0200, Giulio Bottazzi wrote:
> Hi all,
> a simple question: given that the function "gsl_vector_realloc" does
> not esist, how do you manage to increase an alredy existing gsl_vector?
> (I mean, without using plain C arrays).
>
> Giulio.
> _______________________________________________
> Help-gsl mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/help-gsl
--
james bergstra
http://www-etud.iro.umontreal.ca/~bergstrj