Please educate me on shared data between instances


#1

My C++ and plugin development (with regular refactoring ;-) ) have improved nicely in the last 8 months. 

But this is something I am still clueless about:

If I need pre-calculated data, like wave tables for modulation, how should I declare them, so that each next plugin instance does not have to perform the same calculations?

And: I guess binary data, like images etc, will already be shared between instances? Correct?

Any links or explanation are very much appreciated!

Peter


#2

I keep getting told off for using a Singleton class. 

So since this morning*, I've started using

SharedResourcePointer<SharedStuff> c; 

For some of what was previously in singletons.  Where SharedStuff is one of a few possible classes.

Hopefully I'm doing this right.  The way I've gone for it is to have a member variable of my PluginProcessor class own SharedStuff.  This means a version of it is called when the plugin is loaded. 

Then in other bits of the plugin where the class is called I also have the same SharedResourcePointer<SharedStuff> declared.   There is only ever one instance of the SharedStuff class, and when the plugins are all removed from the host it should be deleted. 

For a class that is called infrequently I have a static method in SharedStuff which is something like: 

void SharedStuff::do(x) {

  SharedResourcePointer<SharedStuff> c;

  c->actuallyDoStuff(x); 

}

Which saves me some typing, I can just call SharedStuff:do(...) and not worry about having to declare the pointer each time. 

More here: 

http://www.juce.com/forum/topic/sharedresourcepointer

Does that help? 

J. 

 

*and as someone had just reported a crash involving a singleton when running auval that I couldn't repeat but looked weird..