|
-
September 8th, 2008, 10:07 PM
#1
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!
-
September 8th, 2008, 10:50 PM
#2
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.
-
September 9th, 2008, 12:28 AM
#3
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).
-
September 9th, 2008, 12:49 AM
#4
Re: What is the overhead for const class/functions in C++
 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?
Last edited by _uj; September 9th, 2008 at 03:11 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|