Re: [osg-users] better use smart-pointers or plain pointers in this case?

2009-03-26 Thread Cory Riddell
Christian Sam wrote:
> i think if i use smart-pointers, i would be able to check if the actual 
> polygons in the scenegraph are still valid (check  the ref counter) without 
> the need of a dirty flag. 
> but if the polygons get changed/deleted (e.g. when i want to load a new set 
> of polygon features) the properties i'm pointing to wouldn't be deleted as 
> long as the smart-pointers are referencing them.
>   

You say that like it's a bad thing. If you use bare pointers, are you
ever going to encounter a situation where you have a pointer to
something that's been deleted?

Using smart pointers (or any RAII wrapper object) is rarely a bad idea.
I would be worried however, about overloading the meaning of the
reference counter to also indicate dirtiness. I would be tempted to add
an isDirty() method. That way you can use a bool or the reference count
and can easily change from one implementation to another.

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


[osg-users] better use smart-pointers or plain pointers in this case?

2009-03-26 Thread Christian Sam
Hi,

i'm working on a point-in-polygon test. my current implementation has a list 
with plain pointers that hold references to the polygons' properties. (i use 
them to ease the calculating of an inside-result for that polygons)


Code:

class FetchedPolygon {

public:

FetchedPolygon(osg::Geometry* geom = NULL, osg::Vec3Array* verts = 
NULL);

osg::Geometry* geometry;
osg::Vec3Array* vertices;
std::vector primitiveSets;
};

std::map fetchedPolygons;




before, i used smart-pointers to reference the polygons. (of course) it works 
both ways, but i can't decide what typ of referencing to use.

i think if i use smart-pointers, i would be able to check if the actual 
polygons in the scenegraph are still valid (check  the ref counter) without the 
need of a dirty flag. 
but if the polygons get changed/deleted (e.g. when i want to load a new set of 
polygon features) the properties i'm pointing to wouldn't be deleted as long as 
the smart-pointers are referencing them.

i think its hard to give a rule of thumb when to use smart-pointers. in general 
i'm using them when objects (especially for the scenegraph) are created - as 
long as they won't be attached to another scenegraph-object on the next line. 
i don't use them to reference these already allocated objects, e.g. when they 
are passed to another function, i would use a local pointer inside.


so what your suggestions? Thanks in advance,
christian

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





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