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

Cory Riddell cory at codeware.com
Thu Mar 26 06:22:52 PDT 2009

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.


More information about the osg-users mailing list