EDIT: The OP comment explains that the data store will be read by code running on multiple threads, and updated by code on the same thread. My previous answer no longer applies. Here is the best answer.
Do not use a global variable to store the storage instance. This will open the door to many subtle mistakes that can haunt you for a long time. You must provide read-only read access in the repository. Your message stream must have read and write access.
Make sure your read methods in the data store are marked as const . Then create one instance of the data warehouse and place the pointer to it in the global variable const . Your GetInstance stream should have a different mechanism for obtaining a non-constant pointer (add the public static GetInstance method, as suggested by @Mats).
My previous answer: If you are sure that there will always be only one instance of the data store, do not skip it.
Global variables are not approved, and some languages ββ(Java and C #) outlaw them. So in C # and Java, instead, you are using static class members that are pretty much the same (with exactly the same problems).
If you can put one instance in the global variable a const , you should be fine.
If you are doing multithreading, you need to make sure your store is thread safe, otherwise there will really be bad things.
source share