Hi Björn,

Returning a ref_ptr<> is more safe w.r.t memory management, forcing
the user to use ref_ptr<> themselves, but no as efficient as just
returning a C pointer.

In my own code I typically just pass a C pointer back as as long as
your aware of what you are doing avoiding the pitfalls isn't
difficult.

Robert.

On 1 October 2013 12:45, Björn Blissing <bjorn.bliss...@vti.se> wrote:
> Hi,
>
> I was looking at Don Burns text from 2003 about reference pointers in osg 
> (sadly no longer available online, although it can be found via Internet 
> Archive sites.) But this got me thinking about the suggested pattern for 
> returning pointers from methods.
>
> Looking through different parts of the osg source code you can find two 
> different patterns for returning pointers of object whose class inherits from 
> osg::Referenced.
>
> Pattern 1:
>
> Code:
> osg::ref_ptr< osg::Node> createObject()
> {
>     osg::ref_ptr< osg::Node > objectPtr = new osg::Node;
>     return objectPtr;
> }
>
>
>
> Pattern 2:
>
> Code:
> osg::Node* createObject()
> {
>     osg::ref_ptr< osg::Node > objectPtr = new osg::Node;
>     return objectPtr.release();
> }
>
>
>
> Is one of these preferred? If so why?
>
> Regards
> Björn
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=56560#56560
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to