Re: safe alternative to va_arg
Fabian wrote:
Hello Uli,
4. Classes that only have static functions are conveniently replaced with
namespaces.
This one was just the first step. I thought about writing different
implementations using the factory method pattern later. I.e. different
methods of error output (cerr, log file, whatever...). How big is the
performance loss for the virtual method call in this case?
The answer to pretty much every performance question is: you have to measure
it. Anyway, estimations are possible...
So, typically, calling a function means fetching the address of that
function from somewhere and then jumping to it. With a virtual function,
all that changes is that the place where you read that function's address
from is relative to the object. In other words, it's like writing to an int
on the stack compared to writing an int via a pointer to it.
Further, since we are talking about logging, the function call actually
involves IO, which is by leagues slower than a simple memory accesses like
virtual function calls.
Summary: you won't notice the overhead.
BTW: a very convenient feature of C++ IOStreams is the overloaded rdbuf()
function. Using that, you can easily redirect a stream to stdout, a file or
any other stream:
int main() {
std::ofstream out("program.log");
std::cout.rdbuf(out.rdbuf());
:
The output via std::cout is now redirected to a file.
Uli
--
C++ FAQ: http://parashift.com/c++-faq-lite
Sator Laser GmbH
Gesch??ftsf??hrer: Michael W??hrmann, Amtsgericht Hamburg HR B62 932