0
0
0nk0l0g2016-04-04 10:40:56
C++ / C#
0nk0l0g, 2016-04-04 10:40:56

Why is it better not to use static constructors?

I heard that it is better to do without static constructors and destructors in the code. Especially if the project is big. What is the reason for this and is the advice correct?
Thanks

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
AtomKrieg, 2016-04-04
@AtomKrieg

Static constructs (eg " static const Foo & F = * new Foo ( ) ; " ) can leak memory. If LLVM is built as a dynamic link library, it can be reloaded an unlimited number of times, and one instance of 'Foo' will be created in each iteration of the load.
Also, if LLVM is built on Windows MSVC 2013 (which supports LLVM), then the static layer creation function is thread-unsafe (safe since MSVC 2015). Some variants of LTO will create a thread for each object.
Well, here they also write about the speed of launching the application
llvm.org/docs/CodingStandards.html#do-not-use-stat...
In short, the user will wait a long time before the windows appear and the buttons can be pressed. It is better to create singletons in the background while the interface pretends that the application is fully loaded and ready to go.

I
iv_k, 2016-04-04
@iv_k

if you mean static objects in the global scope, then the constructors are called before the function and main, the destructors after exiting it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question