no downside to smart pointers - don't lose "this" keyword
[Edit] i was wrong
one downside is that you must pass the smart pointer always. in essence, this takes away the "this" keyword. example where i learned this(psuedocode)
class Resource
has std::list of weak ptrs to Instances
class Instance
has smart pointer to Resource
has a member function to change the Resource
if i want to assign a resource to Instance, i can not make instance intelligently pass itself to Resource(and even more important resource pass itself to other subsystems ie loading queue) without sending it the smart pointer of itself
it is possible by doing
AssignResource(ResourcePtr pRes, InstancePtr pThis);
but i have never had to pass an object a pointer to itself so this is really ... fairly ugly i think
by removing "this" u really lose a powerful keyword
[Edited by - yoshscout on September 29, 2007 3:58:11 PM]
It's perfectly possible to use the this keyboard. If you're using Boost's smart pointers, use the shared_from_this idiom. It's in the documentation.
well it seems to me like a pretty good design for a resources to be queued to the background loading thread as objects are created that require the resource(it is more container like)
additionally when no objects are using a resource you have a way of catching that in the objects destructor(again more container like)
the only ways to solve this is to keep a weak ptr filled in by the smart pointer the object was created by, or to change the design to have a 3rd class baby sit all of this(constructs the object - passes it to resource - queues it to resource loader if needed - returns object)
additionally when no objects are using a resource you have a way of catching that in the objects destructor(again more container like)
the only ways to solve this is to keep a weak ptr filled in by the smart pointer the object was created by, or to change the design to have a 3rd class baby sit all of this(constructs the object - passes it to resource - queues it to resource loader if needed - returns object)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement