What is the overhead for const class/functions in C++
I am very confused...here is the original question:
What sort of performance overhead is incurred when using const in C++ programs to create classes and member functions that are considered to be ‘const correct’?
Really appreciate any help as I am very clear about the concept "overhead" in general.
Thank you so much!
Re: What is the overhead for const class/functions in C++
The idea is that, at least in some cases, the compiler is better able to optimize const-correct functions. So really there should be negative overhead, if any.
Of course, the degree of slowdown during compilation resulting from the extra check is probably positive, but likely negligible.
Re: What is the overhead for const class/functions in C++
I only see a performance overhead on the compiler, who has more checks to do. Because a const in-correct program will not build (and run).
Re: What is the overhead for const class/functions in C++
Quote:
Originally Posted by lqakane
What sort of performance overhead is incurred when using const in C++ programs to create classes and member functions that are considered to be ‘const correct’?
Really appreciate any help as I am very clear about the concept "overhead" in general.
"Overhead" usually means what you pay extra for a feature in terms of more memory and/or slower execution.
There's an old "truth" in programming saying that introducing restrictions is good both for programmers and compilers. Constness is a restriction so it shouldn't have any overhead at all, rather the opposite. Okay there may be more work for the compiler but that doesn't count as overhead of your program because the compiler isn't part of your program.
Where did you get this question from?