I'm using an unmanaged library (written in C++) in my code (C#). All the methods provided by the library are static. I use P/Invoke to communicate with the library. Here's the way the library works:
- There's an initialization method that you need to call before calling all the other methods (this takes one parameter and that parameter can only be set during initialization).
- There's a settings method to change different settings for the library, you need to run this if you need to change the way the library works (more like fine-tuning the library). Settings can be changed any time.
- There is a method that takes an array of numbers, and returns another array. Let's call this the intermediate operation. This operation takes a while, so I'd like to cache it and prevent calculating it every time.
- The array returned by the previous method (intermediate operation) is an input to the last method that creates the result. Let's call this the main operation
I'd normally like to have different instances of the library, one with settings A and the other one with settings B. As the library is static, I can't.
How can I wrap this library in an instance class? Probably, every instance of my class will need to load a new instance of the library in memory (as every instance of the library itself is static, and you can't have two different setting in one instance of the library).
Is there a workaround for this, other than re-writing the library (as I don't have any control on how it's written)?
And I'd really like to be able to handle parallel calls to operation methods.