I have few unique objects (like keyboard configuration, lookandfeel settings, etc) that I want to share between all opened VST/AU plugins. I thought doing them Singleton, but i read this from Jules:
Sounds like all you need to do is to hold a static ReferenceCountedObjectPtr in yourClass and in getInstance() just
return this ReferenceCountedObjectPtr (create one if not exists).
The ReferenceCountedObject will take care to all the rest…
Well, unless there’s something I’ve been missing, since both of the plug-ins are in the same process they share the same heap, and they both use the static Ptr which they also share in the code space to point to the instance.
You can use a static, but need be a bit smarter about it. When each plugin releases its pointer to the object, it should check whether its ref count has now gone down to 1 (i.e. no other plugin instances are using it, and only the static pointer is keeping it alive). In that case, it should zero the static pointer to make sure the object gets cleared up.
Hmm okay so you are saying that when a DLL is loaded into a process there is only one instance, therefore only one set of variables with static storage duration.
Thx guys, I think I could try it myself now on my PC.
A last question, does it work on a Mac? (I wont have a Mac until 2014 or so… but I need to create an architecture that actually works on both plataform.