Any known gotchas with SimObjectPtrs (aka SmartPointers) ?
by Orion Elenzil · in Torque Game Engine · 01/10/2007 (2:06 pm) · 2 replies
Hey all -
i'm working on a new GuiControl which needs to refer to a GameBase object.
it's going to access this object every frame, and there may be quite a few of these GuiControls at once (couple hundred) , so instead of storing the GameBase's simID and using Sim::findObject(), it seems more performant to store a pointer to the object.
so i'm using a SimObjectPtr, and it seems to be working great.
i set up the pointer,
and when the pointee is deleted, the pointer magically goes to NULL.
hooray!
but i'm a scaredy-cat and worry about magical things.
are there known gotchas around this mechanism ?
it would seem that i don't need to use the onDeleteNotify() mechanism with this, if all i want to do when the pointee is deleted is set the pointer to NULL. true ?
i know this is pretty vague.
tia, ooo
i'm working on a new GuiControl which needs to refer to a GameBase object.
it's going to access this object every frame, and there may be quite a few of these GuiControls at once (couple hundred) , so instead of storing the GameBase's simID and using Sim::findObject(), it seems more performant to store a pointer to the object.
so i'm using a SimObjectPtr, and it seems to be working great.
i set up the pointer,
and when the pointee is deleted, the pointer magically goes to NULL.
hooray!
but i'm a scaredy-cat and worry about magical things.
are there known gotchas around this mechanism ?
it would seem that i don't need to use the onDeleteNotify() mechanism with this, if all i want to do when the pointee is deleted is set the pointer to NULL. true ?
i know this is pretty vague.
tia, ooo
About the author
Torque 3D Owner Stephen Zepp
onDeleteNotify() is for handling things like having your pointer being part of a linked list, so you can clean it up prior to the pointer actually becoming invalid. Since onDeleteNotify() calls are performed prior to the actual freeing of memory, you can still utilize the pointer for cleanup during the call.
The above of course is assuming that you've properly used registerReference() on the pointer to setup the notification.