selective function call

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all,

I am trying to write a smart logger that can be activated/deactivated at
run-time. I have a print function for the logger that gets va_list:

	void tLogger::print(const char *format, ...) {
		if (!is_activated())
			return;
		va_list marker;
		va_start(marker, format);
		etc. etc.


Trouble is with performance. When I call the print function while the
logger is not activated arguments are still passed to the function. This
is very time-consuming.

Is there a way to avoid passing unnecessarily extra arguments?

Obviously I can write my code as:

 	if (logger->is_activated())
		logger->print("%d\n", ackerman(5,5));

But this is very tiring.
I created a MACRO

	#define LOG if (logger->is_activated()) logger->print

and use it:
	LOG("%d\n", ackerman(5,5));

but this seems to me a very fragile solution.

I tried an inline function (hoping for the optimizer would kick in) but
it was no good.

Is there an more elegant solution for this?

Hayim.


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux