Method for counting instances of a plug-in


#1

Hi,

Is there a safe way for counting the number of intances of a certain plug-in running inside a host?


#2

a static int? Should be pretty safe.


#3

yeah i always do something like:

MyPlugin.h

class MyPlugin { //... static int numInstances; //...

MyPlugin.cpp

[code]int MyPlugin::numInstances = 0;

MyPlugin::~MyPlugin ()
{
if (–MyPlugin::numInstances == 0)
{
// shared deinitialization when all instances off
}
}

AudioFilterBase* createPluginFilter()
{
if (MyPlugin::numInstances++ == 0)
{
// shared initialization among instances
}

return new MyPlugin();

}
[/code]

and it works like a charm !


#4

thanks, thats a good idea that I didn’t think of.


#5