Boost logo

Geometry :

Subject: Re: [geometry] Populating and destructing multi geometries
From: Tomislav Maric (tomislav.maric_at_[hidden])
Date: 2013-05-18 17:14:16


Hi,

I don't think there is a need to create the new multi_linestring object
using the "new" operator, and worry about deletion of this object using
"delete" or any of its elements in the same way. You can use the object
directly :

==
multi_linestring mls;
for (...) { // loop through lines in Perl data structure
     linestring ls;
     for (...) { // loop through points in Perl data structure
         ls.push_back(av_fetch_point_xy(innerav));
     }
     mls->push_back(ls);
}
==

and then let the destructor of the multi_linestring object be called as
it goes out of scope, as well as the destructors of all the elements.

Best regards,
Tomislav

On 05/18/2013 09:48 PM, Alessandro Ranellucci wrote:
> Hello,
>
> I'm the maintainer of the Perl bindings (Boost::Geometry::Utils) and
> I'm tracking down a memory leak that I introduced in the code that
> transforms Perl data structures to multi_linestring geometries.
>
> First off, I couldn't find any examples about how to populate multi
> geometries. This is what I'm doing now:
>
> ==
> multi_linestring* mls = new multi_linestring();
> for (...) { // loop through lines in Perl data structure
> linestring* ls = new linestring();
> for (...) { // loop through points in Perl data structure
> ls->push_back(av_fetch_point_xy(innerav));
> }
> mls->push_back(*ls);
> }
> ==
>
> Does this look correct?
>
> Now, how am I supposed to delete the multi_linestring object with all
> of its linestrings? 'delete mls' doesn't seem to free everything.
> Am I supposed to walk it myself and delete the individual linestrings?
>
> Thank you very much in advance,
>
> - Alessandro
>
> _______________________________________________
> Geometry mailing list
> Geometry_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/geometry


Geometry list run by mateusz at loskot.net