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

Christian Sam osgforum at tevs.eu
Thu Mar 26 05:15:36 PDT 2009


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)


class FetchedPolygon {


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

	osg::Geometry* geometry;
	osg::Vec3Array* vertices;
	std::vector<osg::PrimitiveSet*> primitiveSets;

std::map<const unsigned int, FetchedPolygon> 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,

Read this topic online here:

More information about the osg-users mailing list