Subject: CGAL users discussion list
List archive
- From: Alessandro Attanasi <>
- To: Philipp Moeller <>
- Cc:
- Subject: Re: [cgal-discuss] lower_hull_2() problem
- Date: Wed, 15 Jan 2014 23:45:59 +0100
Ok, but why that procedure was working using all convex_hull functions?
I started from the cgal example
I freed the malloc at the end :)
On 15 January 2014 23:31, Philipp Moeller <> wrote:
Alessandro Attanasi <> writes:Why would you ever call malloc instead of new in such a situation? It is
> Sorry, really stupid error :P. It works as expected!
>
> Just last question about this problem: if I want to use C pointers instead
> of stl iterators, why this code is wrong? It gives to me zero points on the
> lower hull (I tried to use the same logic of the example for convex hull
> computation)
>
> K::Point_2 *ptr2;
>
> K::Point_2 *result2 = NULL;
>
> result2 = (K::Point_2*)malloc(totPoints * sizeof(K::Point_2));
>
> ptr2 = CGAL::lower_hull_points_2( points, points+totPoints, result2 );
exactly where your problem comes from. You cannot simply use raw
uninitialized memory as an OutputIterator. You should wrap the pointer
into a raw_storage_iterator provided by the standard header memory. [1]
You also need to take special care when releasing the memory (call the
destructor explicitly).
Footnotes:
>
>
> ch_points = (ptr2 - result2);
>
> std::cout << "6) Points on the lower hull = " << ch_points << std::endl;
>
> for(int i =0;i<ch_points;i++)
>
> {
>
> std::cout << result2[i] << std::endl;
>
> }
[1] http://en.cppreference.com/w/cpp/memory/raw_storage_iterator
- [cgal-discuss] lower_hull_2() problem, Alessandro Attanasi, 01/14/2014
- Re: [cgal-discuss] lower_hull_2() problem, Philipp Moeller, 01/15/2014
- Re: [cgal-discuss] lower_hull_2() problem, Alessandro Attanasi, 01/15/2014
- Re: [cgal-discuss] lower_hull_2() problem, Philipp Moeller, 01/15/2014
- Re: [cgal-discuss] lower_hull_2() problem, Alessandro Attanasi, 01/15/2014
- Re: [cgal-discuss] lower_hull_2() problem, Philipp Moeller, 01/15/2014
- Re: [cgal-discuss] lower_hull_2() problem, Alessandro Attanasi, 01/15/2014
- Re: [cgal-discuss] lower_hull_2() problem, Philipp Moeller, 01/16/2014
- Re: [cgal-discuss] lower_hull_2() problem, Alessandro Attanasi, 01/16/2014
- Re: [cgal-discuss] lower_hull_2() problem, Philipp Moeller, 01/16/2014
- Re: [cgal-discuss] lower_hull_2() problem, Alessandro Attanasi, 01/17/2014
- Re: [cgal-discuss] lower_hull_2() problem, Alessandro Attanasi, 01/15/2014
- Re: [cgal-discuss] lower_hull_2() problem, Philipp Moeller, 01/15/2014
- Re: [cgal-discuss] lower_hull_2() problem, Alessandro Attanasi, 01/15/2014
- Re: [cgal-discuss] lower_hull_2() problem, Philipp Moeller, 01/15/2014
- Re: [cgal-discuss] lower_hull_2() problem, Alessandro Attanasi, 01/15/2014
- Re: [cgal-discuss] lower_hull_2() problem, Philipp Moeller, 01/15/2014
Archive powered by MHonArc 2.6.18.