04-30-2015, 03:41 AM
Hi there, I'm new here and will probably be contributing bits here and there whenever I find time.
Now for the other reason behind this thread. I have a static (member) object Tracer::m_NormalTable and need to make sure it isn't used by other static objects before it's initialized. (i.e., calls Tracer::Trace)
Further explanation: https://isocpp.org/wiki/faq/ctors#static-init-order
There are two options:
Which one should be preferred for this project? Option 1 is safer, but causes a small memory leak when the program exits. Option 2 can have catastrophic consequences if someone doesn't know about this.
Now for the other reason behind this thread. I have a static (member) object Tracer::m_NormalTable and need to make sure it isn't used by other static objects before it's initialized. (i.e., calls Tracer::Trace)
Further explanation: https://isocpp.org/wiki/faq/ctors#static-init-order
There are two options:
- Initialize on first use
- Everything works fine. Nobody else needs to care about this.
- m_NormalTable isn't destructed and 'leaks'
- Everything works fine. Nobody else needs to care about this.
- Only add a big fat comment to the Tracer class
- Has a 50/50 chance of spawning Godzilla, causing cancer or starting a thermonuclear war when someone does use it in another static object
- Doesn't leak
- Has a 50/50 chance of spawning Godzilla, causing cancer or starting a thermonuclear war when someone does use it in another static object
Which one should be preferred for this project? Option 1 is safer, but causes a small memory leak when the program exits. Option 2 can have catastrophic consequences if someone doesn't know about this.