The algorithm copies things from the end of the vector into the locations of
the elements to be deleted, and then shortens the vector by that amount. So
if your vector is a, b, c and you want to remove 'a', first c gets copied
into a's spot (c, b, c), then the vector is resized (c, b). I guess that
would break Switch nodes etc.

Normally it would be fine with me if this doesn't make it into osg, but the
use of friends in osg::Node means that it's impossible to correctly
reimplement osg::Group::removeChildren without changing the Node header.
Maybe it could be added as an osg::UnorderedGroup, or the current osg::Group
could become osg::OrderedGroup, etc.

- Max

On Fri, Jul 31, 2009 at 5:02 PM, Thrall, Bryan <
[email protected]> wrote:

> Max Bandazian wrote on Friday, July 31, 2009 12:54 PM:
> >            if (_children.size() == numChildrenToRemove)
> >             {
> >                _children.clear();
> >             }
> >             else
> >             {
> >                int numThingsToCopy = std::min(numChildrenToRemove,
> >                _children.size() - numChildrenToRemove);
> >                std::copy(_children.end() - numThingsToCopy,
> _children.end(),
> >             _children.begin() + pos);
> _children.resize(_children.size() -
> > numChildrenToRemove); }
> >
> > With this change, removing the 30,000 nodes takes less than 1 second.
> It does
> > change the semantics of removing children from a group, in that the
> children
> > will be in a different order rather than just having their index
> changed. In
> > my opinion it's worth it for the performance gain.
>
> That sounds pretty nice, but I must be missing something, because that
> code looks like it does not change the order of the children. What's the
> down side again?
>
> --
> Bryan Thrall
> FlightSafety International
> [email protected]
> _______________________________________________
> osg-submissions mailing list
> [email protected]
>
> http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org
>
_______________________________________________
osg-submissions mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org

Reply via email to