Is global memory initialized in C++? And if so, how?
(Second) clarification:
When a program starts up, what is in the memory space which will become global memory, prior to primitives being initialized? I’m trying to understand if it is zeroed out, or garbage for example.
The situation is: can a singleton reference be set – via an instance() call, prior to its initialization:
MySingleton* MySingleton::_instance = NULL;
and get two singleton instances as a result?
See my C++ quiz on on multiple instances of a singleton…
Yes global primitives are initialized to NULL.
Example:
You cannot make any assumptions about classes, structs, arrays, blocks of memory on the heap…
It’s safest just to always initialize everything.