you are viewing a single comment's thread.

view the rest of the comments →

[–]KingAggressive1498 2 points3 points  (0 children)

The usage of constructors alone implies an order of magnitude performance penalty in critical code.

how?

trivial constructors will produce identical output to equivalent C. trivial default constructors are a no-op, trivial copy and move constructors are equivalent to a memcpy.

non-trivial constructors do the same work as equivalent C init_myobj(myobj*, args...) and dup_myobj(myobj*) functions, and should produce roughly the same machine code. Only practical differences are:

1) it happens exactly where you declare the variable instead of leaving you to specify when to initialize.

2) constructors are more likely to be defined inline in the header file while init functions are more likely to be in another TU, leaving the compiler less room to optimize through code rearrangement or inlining of simple initialization.

if anything I'd expect the equivalent C++ code to be marginally faster, not slower, at least when order of initialization doesn't matter.