Subject: CGAL users discussion list
List archive
Re: [cgal-discuss] How to copy double* X double* Y to std::list<Point_2> points
Chronological Thread
- From: "Laurent Rineau (GeometryFactory)" <>
- To:
- Subject: Re: [cgal-discuss] How to copy double* X double* Y to std::list<Point_2> points
- Date: Tue, 5 Oct 2010 15:14:54 +0200
- Organization: GeometryFactory
On Tuesday 05 October 2010 14:59:23 Benoît Presles wrote:
> Hello everybody,
>
> I am looking for a nice way to copy my data: double* X, double* Y to a
> list of Point_2.
> Here is my code:
> //My data (example)
> double X[]={1,2,3,5,6};
> double Y[]={-10,7,5,9,5};
> //My output:
> std::list<Point_2> points;
> //for loop
> for(int i=0; i<5; ++i)
> {
> //std::cout << X[i] << " " << Y[i] << std::endl;
> points.push_back(Point_2(X[i], Y[i]));
> }
>
> As one can notice, I do a "for loop" to copy my data. It works but I am
> looking for a better way. Indeed, when my array X (or Y) is very big,
> the code is a bit slow.
You should use std::vector instead of std::list, and reserve the memory:
points.reserve(n);
where n is the size of your arrays.
--
Laurent Rineau, PhD
R&D Engineer at GeometryFactory http://www.geometryfactory.com/
Release Manager of the CGAL Project http://www.cgal.org/
- [cgal-discuss] How to copy double* X double* Y to std::list<Point_2> points, Benoît Presles, 10/05/2010
- Re: [cgal-discuss] How to copy double* X double* Y to std::list<Point_2> points, Laurent Rineau (GeometryFactory), 10/05/2010
- Re: [cgal-discuss] How to copy double* X double* Y to std::list<Point_2> points, Benoît Presles, 10/05/2010
- Re: [cgal-discuss] How to copy double* X double* Y to std::list<Point_2> points, Laurent Rineau (GeometryFactory), 10/05/2010
- Re: [cgal-discuss] How to copy double* X double* Y to std::list<Point_2> points, Benoît Presles, 10/05/2010
- Re: [cgal-discuss] How to copy double* X double* Y to std::list<Point_2> points, Laurent Rineau (GeometryFactory), 10/05/2010
- Re: [cgal-discuss] How to copy double* X double* Y to std::list<Point_2> points, Benoît Presles, 10/05/2010
- Re: [cgal-discuss] How to copy double* X double* Y to std::list<Point_2> points, Laurent Rineau (GeometryFactory), 10/05/2010
Archive powered by MHonArc 2.6.16.