I was worried for a while, but I did not find a good resource on this. I have some global variables in my code. Obviously, they are initialized in some order, but is this a memmory needed for all those objects that were reserved before any initialization started?
here is a simple example of what might go wrong in my code and how I can use the answer:
I had a map<RTTI, object*> objectPool that contains samples of each class in my code, which I used to load objects from a file. To create these samples, I use some global variables to introduce an instance of the objectPool class. But sometimes, these instance instances were initialized before ObjectPool. And this generated runtime error.
To fix this error, I used the delayed initializer map<RTTI,object*>* lateInitializedObjectPool; . Now each instance first checks to see if objectPool is initialized and initializes it if not, and then it is embedded in the object pool. Everything seems to be working fine, but I'm worried even if the memmory needed for the object pool pointer is not reserved before other classes begin to represent themselves and could cause access violation.
c ++ global-variables
Ali1S232
source share