Robert Osfield schrieb:
Hi Randall,
Its expensive to pass ref_ptr<> around on the stack as they call
ref()/unref() for each temporary ref_ptr<> created, one a ref() for
the final destination. If the Object has a ref count mutex on it then
the cost of this can be high.
It would of course be safe to pass back a ref_ptr<> to try and prevent
"potential" abuse by end users, however, I'm very much of the
inclination that we should assume users know what they are doing and
not to code things in a way that adds extra performance overhead that
might help out users who don't know what they are doing.
OpenGL also has the same policy, it doesn't go round trying to catch
and fix every naughty usage of it, its designed to be fast.
Robert.
Hi,
I had wanted to ask about this too. I often use ref_ptr<> as
return-values for functions, so maybe I should check if those are
performance-critical.
So the safe and fast way for the knowing user would be to return naked
pointers but to assign them to ref_ptr directly in the calling function?
i.e.:
osg::ref_pgr<osg::Geode> g = myStupidFunction();
osg::Geode* myStupidFunction(){
...
osg::ref_ptr<osg::Geode> x = new osg::geode();
return x.get();
}
or would it even be safe to use a naked pointer in the calling function?
i.e.:
osg::Geode* myStupidFunction(){
...
osg::Geode* x = new osg::geode();
return x;
}
Regards,
Andreas
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/