I think the "best practice" is to only use the ref_ptr structure to refer to objects derived from Referenced as you said. But you can get away with using bare pointers whenever you know you're going to do some operation that will increment the ref count anyway, ex. adding it to an existing group. OSG itself is somewhat relaxed in the sense that all its function calls accept and return bare pointers to Referenced objects. But that's one of the nice things about an intrusive reference count (as opposed to boost::shared_ptr, for example) -- you don't have to be as fussy about using the ref_ptr structure everywhere.
-Nathan -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED] Sent: Wednesday, April 09, 2008 11:06 AM To: osg-users@lists.openscenegraph.org Subject: [osg-users] use of ref_ptr I just started using OSG and have never used ref_ptr's before, though I've read the "A Short Introduction to the Basic Principles of the Open Scene Graph" and belive I understand the concept. But I wonder if you have any advice on the use of ref_ptr's on OSG objects, and If you use them in some standard way. I recon all the objects that inherits from "Referenced" should use ref_ptr for safer memory alloction/deleting, but I guess it's just a subjective choice. The tutorials though use "dumb" pointers as in the Basic Geometry example: " ... int main() { ... osg::Group* root = new osg::Group(); osg::Geode* pyramidGeode = new osg::Geode(); osg::Geometry* pyramidGeometry = new osg::Geometry(); " but i guess it's just for simplicity. In the guide "A Short Introduction to the Basic Principles of the Open Scene Graph" on the use of ref_ptr, they first create a node using ref pointer, then they add a node using new, and say: " Line 25 does more or less the same thing as the previous case. The difference is that the geode is allocated with new and added as group's child in a single line of code. This is quite safe, too, because there are not many bad things that can happen in between (after all, there is no in between.) " that may be a little missleading since it's not a smart pointer, and needs to be deleted explicitly. Erlend _______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.or g _______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org