help-gsl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-gsl] Using vector instead of arrays ?


From: Kevin Thornton
Subject: Re: [Help-gsl] Using vector instead of arrays ?
Date: Tue, 26 Jul 2005 12:15:35 -0700 (PDT)

Many of the GSL functions take the pointer to double
and the size of the array as arguments.  Since the C++
vector is a contiguous-memory container, a pointer to
the first element does the trick:

std::vector<double> data;
//fill data...

//call the gsl function
gsl_foo( &data[0], data.size() );
//alternately, but less easy to read:
gsl_foo( &*data.begin(), data.size() );

This doesn't work with std::list, or other containers
that don't store memory in contiguous blocks.  

--Kevin
--- Maxime Boissonneault
<address@hidden> wrote:

> Hello,
> I was wondering, is there a way to use
> vector<double> instead of double 
> *, and still be able to use GSL functions ?
> 
> If not, is there a way to cast a vector<double> to a
> double * ?
> 
> 
> -- 
> Maxime Boissonneault
> address@hidden
>
---------------------------------------------------------
> Le génie consiste à voir ce que tout le monde a vu
> et à penser ce que personne n'a pensé. (Albert
> Einstein)
> 
> 
> 
> _______________________________________________
> Help-gsl mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/help-gsl
> 


Kevin Thornton
Committee on Genetics
University of Chicago
http://www.molpopgen.org


                
____________________________________________________
Start your day with Yahoo! - make it your home page 
http://www.yahoo.com/r/hs 
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]