SharedResourcePointer on the stack?


#1

Is there an obvious reason to NOT use SharedResourcePointer on the stack? 

void foo( ) {
    SharedResourcePointer<MySharedData> sharedData;
    useSharedStuff (sharedData->sharedStuff);
}

Edit: I mean with the sharedData "owned" somewhere during the application lifetime.


#2

That's perfectly ok.

The only thing to watch out for would be if you create/destroy a lone SharedResourcePointer repeatedly, so that the underlying resource would get repeatedly created/deleted, which might be a drain on performance. The best way to use them is when you have multiple instances whose lifetimes overlap, but whether they're on the stack or part of an object doesn't matter.


#3

Yep, of course. With that new SharedResourcePointer class i should implement in a more elegant way "the global table of identifiers" that is cached in my bundle. I should have think about that trick before ;-) 

Thanks!