Op 11-Mar-13 23:39, W Karas schreef:
If the performance really matters and I really want to understand what
is going on I usually inspect the assembly output of the compiler and/or
step though the code with the debugger in disassembly mode.
Inspecting the assembly output can lead to sometimes surprising
insights. I see too often that people resort to tricks that make the
code hard to understand and/or brittle because they _believe_ it will
run more efficiently without bothering to actually measure it or
actually checking how it affects the code being generated. More often
than not the hack is no more efficient and quite often even less
efficient than the straightforward implementation.
There are many variables, such as the compiler, (optimization) settings
and the code being compiled, that affect what kind of code will be
generated. For example for virtual functions a vtable is typically used
(I have never seen a C++ compiler that used hash tables for virtual
functions, nor do I see any benefit with that approach), but sometimes
the compiler can skip the vtable lookup if knows at compile time exactly
which function is going to be called, it might even inline that function
in that case.
That being said the following articles should give some insight how
virtual functions are typically done by C++ compilers:
http://en.wikipedia.org/wiki/Virtual_method_table
http://tinydrblog.appspot.com/?p=89001
For exception handling the articles below may give you some insight how
C++ compilers may implement this feature:
http://preshing.com/20110807/the-cost-of-enabling-exception-handling
http://www.systemcall.org/blog/2010/10/zero-cost-exception-handling-in-cpp/