J
jsnX
hi,
i would like to make some code that operates on sets of points - does
convex hulls and other operations. but it looks like i will need a lot
of pointless object copies:
======================================================================================
// point cloud class
class pc : public std::vector<vec2d>
{
// utility methods for operating on lists of points
static pc&
convex_hull(const pc& _1, const pc& _2)
{
// return the convex hull of these two clouds somehow
}
};
pc a = get_a();
pc b = get_b();
pc c = get_c();
pc hull_ab = pc::convex_hull(a, b); // pointless copies from
a and b
pc hull_bc = pc::convex_hull(b, c); // pointless copies from
b and c
pc::iterator alpha = b.begin();
pc::iterator omega = b.end();
pc b_on_both;
for(; alpha != omega; ++alpha )
if ( hull_ab.has(*alpha) && hull_bc.has(*alpha) )
b_on_both.push_back(*alpha); // pointless copies due
to operator=
======================================================================================
how do i avoid all these copies? obviously, there is a way - using
pointers. i could just make pc inherit from std::vector<vec2d*>. but in
books and on the web, i am told that containers of pointers are evil,
so i don't want to implement my class with one! is this a case where
'garbage collection' or 'reference counting' is necessary?
_jsnX
i would like to make some code that operates on sets of points - does
convex hulls and other operations. but it looks like i will need a lot
of pointless object copies:
======================================================================================
// point cloud class
class pc : public std::vector<vec2d>
{
// utility methods for operating on lists of points
static pc&
convex_hull(const pc& _1, const pc& _2)
{
// return the convex hull of these two clouds somehow
}
};
pc a = get_a();
pc b = get_b();
pc c = get_c();
pc hull_ab = pc::convex_hull(a, b); // pointless copies from
a and b
pc hull_bc = pc::convex_hull(b, c); // pointless copies from
b and c
pc::iterator alpha = b.begin();
pc::iterator omega = b.end();
pc b_on_both;
for(; alpha != omega; ++alpha )
if ( hull_ab.has(*alpha) && hull_bc.has(*alpha) )
b_on_both.push_back(*alpha); // pointless copies due
to operator=
======================================================================================
how do i avoid all these copies? obviously, there is a way - using
pointers. i could just make pc inherit from std::vector<vec2d*>. but in
books and on the web, i am told that containers of pointers are evil,
so i don't want to implement my class with one! is this a case where
'garbage collection' or 'reference counting' is necessary?
_jsnX