I have a C++ library that works on some numeric values, this values are not available at compile time but are immediatly available at runtime and are based on machine-related details, in short I need values like display resolution, the number of CPU cores and so on.
The key points of my question are:
- I can't ask to the user to input this values ( both the coders/user of my lib and the final user )
- I need to do this warm up only once the application starts, it's a 1 time only thing
- this values are later used by methods and classes
the possible solutions are:
- build a data structure
Data
, declare someData dummy
wheredummy
is the name of the variable used to store everything and the contructor/s will handle the one time inizialization for the related values - wrap something like the first solution in a method like
WarmUp()
and putting this method right after the start for themain()
( it's also a simple thing to remember and use )
the big problems that are still unsolved are:
- the user can declare more than 1 data structure since
Data
it's a type and there are no restrictions about throwing 2-4-5-17 variables of the same type in C++ - the
WarmUp()
method can be a little intrusive in the design of the other classes, it can also happen that theWarmUp()
method is used in local methods and not in themain()
.
I basically need to force the creation of 1 single instance of 1 specific type at runtime when I have no power over the actual use of my library, or at least I need to design this in a way that the user will immediately understand what kind of error is going on keeping the use of the library intuitive and simple as much as possible.
Can you see a solution to this ?
EDIT:
my problems are also more difficult due to the fact that I'm also trying to get a multi-threading compatible data structure.