Re: [osg-users] using ref_ptr in any case

2017-03-20 Thread Sebastian Schmidt

robertosfield wrote:
> Hi Sebastian,
> 
> Using ref_ptr<> in local scope to objects t that are owned by external
> scope is a good practice but isn't always required.
> 
> If your application is multi-threaded then the external scope could
> unref and objects that you are using, so if you don't have your own
> reference to it it would go out of scope and you'd end up with a
> dangling pointer in your local scope.
> 
> If your application is single threaded then it should be safe to just
> use C pointers in local scope while the object is kept alive by the
> external scope.
> 
> Robert.
> 


Thanks. I would like to stick to multi threading.
Even if it doesnt make sense in local scope i have a consitent way of using 
ref_ptr everytime.

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=70515#70515





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] using ref_ptr in any case

2017-03-20 Thread Robert Osfield
Hi Sebastian,

Using ref_ptr<> in local scope to objects t that are owned by external
scope is a good practice but isn't always required.

If your application is multi-threaded then the external scope could
unref and objects that you are using, so if you don't have your own
reference to it it would go out of scope and you'd end up with a
dangling pointer in your local scope.

If your application is single threaded then it should be safe to just
use C pointers in local scope while the object is kept alive by the
external scope.

Robert.

On 20 March 2017 at 13:41, Sebastian Schmidt  wrote:
> Hi.
> I try to avoid possible memory leaks and currently replacing all pointers of 
> osg object types with ref_ptr.
>
> I read the osgproducer article and some other threads about these reference 
> pointers, but i wonder if there is any advantage for using ref_ptr also in 
> local scope as temporary references to existing pointers.
>
>
> Code:
> osg::ref_ptr pView = dynamic_cast();
>
> [/code]
>
> --
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=70512#70512
>
>
>
>
>
> ___
> 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


[osg-users] using ref_ptr in any case

2017-03-20 Thread Sebastian Schmidt
Hi.
I try to avoid possible memory leaks and currently replacing all pointers of 
osg object types with ref_ptr.

I read the osgproducer article and some other threads about these reference 
pointers, but i wonder if there is any advantage for using ref_ptr also in 
local scope as temporary references to existing pointers. 


Code:
osg::ref_ptr pView = dynamic_cast();

[/code]

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=70512#70512





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org