One of the libraries that we use for our product uses singleton access to access it. I am sure that it is implemented as a static instance (it is not open source). This works well for a single document application, but more than one document can be loaded in our application. I assume access to the instance is written something like this:
Instance* getInstance() { static Instance* inst = new Instance(); return inst; }
In such situations, is there some way to create more than one instance? The only thing I can think of is to have more than process and use some type of IPC to tie it all together. I can't think of anything less hacked.
I asked the provider to implement some type of session token, so I can have several parallel instances, but they are large, and we are small.
Corey
Edit:
- the machine is a windows machine
- global statics is basically a big factory. I need some kind of session token, so I can easily say โfree all resources from this sessionโ (there is no way to re-initialize the global statics that I know about)
Instead of trying to use some dodgy fraud to get what I want, I'm going to wrap it all in my class and add a session key to each recipient. Inside, I will keep track of what has been allocated, adding my own release method to return the resources. This is suboptimal for many reasons, but I can't come up with a better idea.
Thanks everyone for the great feedback.
source share